Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { PlatformType } from '@crowd/types'
import { getNangoToken } from '../../../nango'
import { IGenerateStreamsContext, IProcessStreamContext } from '@/types'
import { HubspotAssociationType, HubspotEndpoint, IHubspotAssociation } from '../types'
import { RequestThrottler } from '@crowd/common'

export const getContactAssociations = async (
nangoId: string,
association: HubspotEndpoint,
type: HubspotAssociationType,
contactId: string,
ctx: IProcessStreamContext | IGenerateStreamsContext,
throttler: RequestThrottler,
): Promise<IHubspotAssociation[]> => {
const config: AxiosRequestConfig<unknown> = {
method: 'get',
Expand All @@ -21,9 +23,9 @@ export const getContactAssociations = async (
const accessToken = await getNangoToken(nangoId, PlatformType.HUBSPOT, ctx)
config.headers = { Authorization: `Bearer ${accessToken}` }

const response = (await axios(config)).data
const result = await throttler.throttle(() => axios(config))

const contactAssociations: IHubspotAssociation[] = response.results
const contactAssociations: IHubspotAssociation[] = result?.data?.results || []

return contactAssociations.filter((a) => a.type === type)
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const getContacts = async (
HubspotAssociationType.CONTACT_TO_COMPANY,
element.id,
ctx,
throttler,
)

if (companyAssociations.length > 0) {
Expand Down