Skip to content

Commit b567dfc

Browse files
authored
Checking primary key maps in while creating/updating in hubspot (#1512)
1 parent dcaeec2 commit b567dfc

File tree

4 files changed

+66
-52
lines changed

4 files changed

+66
-52
lines changed

services/libs/integrations/src/integrations/premium/hubspot/api/batchCreateMembers.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,32 @@ export const batchCreateMembers = async (
4646

4747
for (const crowdField of fields) {
4848
const hubspotField = memberMapper.getHubspotFieldName(crowdField)
49-
if (crowdField.startsWith('attributes')) {
50-
const attributeName = crowdField.split('.')[1] || null
51-
52-
if (
53-
attributeName &&
54-
hubspotField &&
55-
member.attributes[attributeName]?.default !== undefined
56-
) {
57-
hsMember.properties[hubspotField] = member.attributes[attributeName].default
58-
}
59-
} else if (crowdField.startsWith('identities')) {
60-
const identityPlatform = crowdField.split('.')[1] || null
49+
// if hubspot e-mail field is mapped to a crowd field, we should ignore it because
50+
// we handle this manually above
51+
if (hubspotField && hubspotField !== 'email') {
52+
if (crowdField.startsWith('attributes')) {
53+
const attributeName = crowdField.split('.')[1] || null
54+
55+
if (
56+
attributeName &&
57+
hubspotField &&
58+
member.attributes[attributeName]?.default !== undefined
59+
) {
60+
hsMember.properties[hubspotField] = member.attributes[attributeName].default
61+
}
62+
} else if (crowdField.startsWith('identities')) {
63+
const identityPlatform = crowdField.split('.')[1] || null
6164

62-
const identityFound = member.identities.find((i) => i.platform === identityPlatform)
65+
const identityFound = member.identities.find((i) => i.platform === identityPlatform)
6366

64-
if (identityPlatform && hubspotField && identityFound) {
65-
hsMember.properties[hubspotField] = identityFound.username
67+
if (identityPlatform && hubspotField && identityFound) {
68+
hsMember.properties[hubspotField] = identityFound.username
69+
}
70+
} else if (crowdField === 'organizationName') {
71+
// send latest org of member as value
72+
} else if (hubspotField && member[crowdField] !== undefined) {
73+
hsMember.properties[hubspotField] = memberMapper.getHubspotValue(member, crowdField)
6674
}
67-
} else if (crowdField === 'organizationName') {
68-
// send latest org of member as value
69-
} else if (hubspotField && member[crowdField] !== undefined) {
70-
hsMember.properties[hubspotField] = memberMapper.getHubspotValue(member, crowdField)
7175
}
7276
}
7377

services/libs/integrations/src/integrations/premium/hubspot/api/batchCreateOrganizations.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ export const batchCreateOrganizations = async (
4747

4848
for (const crowdField of fields) {
4949
const hubspotField = organizationMapper.getHubspotFieldName(crowdField)
50-
51-
if (hubspotField && organization[crowdField] !== undefined) {
52-
hubspotCompany.properties[hubspotField] = organizationMapper.getHubspotValue(
53-
organization,
54-
crowdField,
55-
)
50+
// if hubspot domain field is mapped to a crowd field, we should ignore it
51+
// because we handle this manually above
52+
if (hubspotField && hubspotField !== 'domain') {
53+
if (organization[crowdField] !== undefined) {
54+
hubspotCompany.properties[hubspotField] = organizationMapper.getHubspotValue(
55+
organization,
56+
crowdField,
57+
)
58+
}
5659
}
5760
}
5861

services/libs/integrations/src/integrations/premium/hubspot/api/batchUpdateMembers.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,32 @@ export const batchUpdateMembers = async (
4343

4444
for (const crowdField of fields) {
4545
const hubspotField = memberMapper.getHubspotFieldName(crowdField)
46-
if (crowdField.startsWith('attributes')) {
47-
const attributeName = crowdField.split('.')[1] || null
48-
49-
if (
50-
attributeName &&
51-
hubspotField &&
52-
member.attributes[attributeName]?.default !== undefined
53-
) {
54-
hsMember.properties[hubspotField] = member.attributes[attributeName].default
46+
// if hubspot e-mail field is mapped to a crowd field, we should ignore it because
47+
// we handle this manually above
48+
if (hubspotField && hubspotField !== 'email') {
49+
if (crowdField.startsWith('attributes')) {
50+
const attributeName = crowdField.split('.')[1] || null
51+
52+
if (
53+
attributeName &&
54+
hubspotField &&
55+
member.attributes[attributeName]?.default !== undefined
56+
) {
57+
hsMember.properties[hubspotField] = member.attributes[attributeName].default
58+
}
59+
} else if (crowdField.startsWith('identities')) {
60+
const identityPlatform = crowdField.split('.')[1] || null
61+
62+
const identityFound = member.identities.find((i) => i.platform === identityPlatform)
63+
64+
if (identityPlatform && hubspotField && identityFound) {
65+
hsMember.properties[hubspotField] = identityFound.username
66+
}
67+
} else if (crowdField === 'organizationName') {
68+
// send latest org of member as value
69+
} else if (hubspotField && member[crowdField] !== undefined) {
70+
hsMember.properties[hubspotField] = memberMapper.getHubspotValue(member, crowdField)
5571
}
56-
} else if (crowdField.startsWith('identities')) {
57-
const identityPlatform = crowdField.split('.')[1] || null
58-
59-
const identityFound = member.identities.find((i) => i.platform === identityPlatform)
60-
61-
if (identityPlatform && hubspotField && identityFound) {
62-
hsMember.properties[hubspotField] = identityFound.username
63-
}
64-
} else if (crowdField === 'organizationName') {
65-
// send latest org of member as value
66-
} else if (hubspotField && member[crowdField] !== undefined) {
67-
hsMember.properties[hubspotField] = memberMapper.getHubspotValue(member, crowdField)
6872
}
6973
}
7074

services/libs/integrations/src/integrations/premium/hubspot/api/batchUpdateOrganizations.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ export const batchUpdateOrganizations = async (
4343

4444
for (const crowdField of fields) {
4545
const hubspotField = organizationMapper.getHubspotFieldName(crowdField)
46-
47-
if (hubspotField && organization[crowdField] !== undefined) {
48-
hubspotCompany.properties[hubspotField] = organizationMapper.getHubspotValue(
49-
organization,
50-
crowdField,
51-
)
46+
// if hubspot domain field is mapped to a crowd field, we should ignore it
47+
// because we handle this manually above
48+
if (hubspotField && hubspotField !== 'domain') {
49+
if (organization[crowdField] !== undefined) {
50+
hubspotCompany.properties[hubspotField] = organizationMapper.getHubspotValue(
51+
organization,
52+
crowdField,
53+
)
54+
}
5255
}
5356
}
5457

0 commit comments

Comments
 (0)