-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(root): Release 2024-11-01 12:40 (#6826)
- Loading branch information
Showing
66 changed files
with
612 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 35 additions & 23 deletions
58
apps/api/src/app/analytics/usecases/hubspot-identify-form/hubspot-identify-form.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,49 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { HttpService } from '@nestjs/axios'; | ||
import { firstValueFrom } from 'rxjs'; | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
import { AxiosError } from 'axios'; | ||
import { HubspotIdentifyFormCommand } from './hubspot-identify-form.command'; | ||
|
||
const LOG_CONTEXT = 'HubspotIdentifyFormUsecase'; | ||
|
||
@Injectable() | ||
export class HubspotIdentifyFormUsecase { | ||
private readonly hubspotPortalId = '44416662'; | ||
private readonly hubspotFormId = 'fc39aa98-4285-4322-9514-52da978baae8'; | ||
|
||
constructor(private httpService: HttpService) {} | ||
|
||
async execute(command: HubspotIdentifyFormCommand): Promise<{ success: boolean; hubspotResponse?: any }> { | ||
const hubspotSubmitUrl = `https://api.hsforms.com/submissions/v3/integration/submit/${this.hubspotPortalId}/${this.hubspotFormId}`; | ||
|
||
const hubspotData = { | ||
fields: [ | ||
{ name: 'email', value: command.email }, | ||
{ name: 'lastname', value: command.lastName || 'Unknown' }, | ||
{ name: 'firstname', value: command.firstName || 'Unknown' }, | ||
{ name: 'app_organizationid', value: command.organizationId }, | ||
], | ||
context: { | ||
hutk: command.hubspotContext, | ||
pageUri: command.pageUri, | ||
pageName: command.pageName, | ||
}, | ||
}; | ||
async execute(command: HubspotIdentifyFormCommand) { | ||
try { | ||
const hubspotSubmitUrl = `https://api.hsforms.com/submissions/v3/integration/submit/${this.hubspotPortalId}/${this.hubspotFormId}`; | ||
|
||
const response = await firstValueFrom(this.httpService.post(hubspotSubmitUrl, hubspotData)); | ||
const hubspotData = { | ||
fields: [ | ||
{ name: 'email', value: command.email }, | ||
{ name: 'lastname', value: command.lastName || 'Unknown' }, | ||
{ name: 'firstname', value: command.firstName || 'Unknown' }, | ||
{ name: 'app_organizationid', value: command.organizationId }, | ||
], | ||
context: { | ||
hutk: command.hubspotContext, | ||
pageUri: command.pageUri, | ||
pageName: command.pageName, | ||
}, | ||
}; | ||
|
||
return { | ||
success: true, | ||
hubspotResponse: response.data, | ||
}; | ||
await this.httpService.post(hubspotSubmitUrl, hubspotData); | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
Logger.error( | ||
`Failed to submit to Hubspot message=${error.message}, status=${error.status}`, | ||
{ | ||
organizationId: command.organizationId, | ||
response: error.response?.data, | ||
}, | ||
LOG_CONTEXT | ||
); | ||
} else { | ||
throw error; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.