Skip to content

Commit

Permalink
Checking primary key maps in while creating/updating in hubspot (#1512)
Browse files Browse the repository at this point in the history
  • Loading branch information
epipav authored Sep 18, 2023
1 parent dcaeec2 commit b567dfc
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,32 @@ export const batchCreateMembers = async (

for (const crowdField of fields) {
const hubspotField = memberMapper.getHubspotFieldName(crowdField)
if (crowdField.startsWith('attributes')) {
const attributeName = crowdField.split('.')[1] || null

if (
attributeName &&
hubspotField &&
member.attributes[attributeName]?.default !== undefined
) {
hsMember.properties[hubspotField] = member.attributes[attributeName].default
}
} else if (crowdField.startsWith('identities')) {
const identityPlatform = crowdField.split('.')[1] || null
// if hubspot e-mail field is mapped to a crowd field, we should ignore it because
// we handle this manually above
if (hubspotField && hubspotField !== 'email') {
if (crowdField.startsWith('attributes')) {
const attributeName = crowdField.split('.')[1] || null

if (
attributeName &&
hubspotField &&
member.attributes[attributeName]?.default !== undefined
) {
hsMember.properties[hubspotField] = member.attributes[attributeName].default
}
} else if (crowdField.startsWith('identities')) {
const identityPlatform = crowdField.split('.')[1] || null

const identityFound = member.identities.find((i) => i.platform === identityPlatform)
const identityFound = member.identities.find((i) => i.platform === identityPlatform)

if (identityPlatform && hubspotField && identityFound) {
hsMember.properties[hubspotField] = identityFound.username
if (identityPlatform && hubspotField && identityFound) {
hsMember.properties[hubspotField] = identityFound.username
}
} else if (crowdField === 'organizationName') {
// send latest org of member as value
} else if (hubspotField && member[crowdField] !== undefined) {
hsMember.properties[hubspotField] = memberMapper.getHubspotValue(member, crowdField)
}
} else if (crowdField === 'organizationName') {
// send latest org of member as value
} else if (hubspotField && member[crowdField] !== undefined) {
hsMember.properties[hubspotField] = memberMapper.getHubspotValue(member, crowdField)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ export const batchCreateOrganizations = async (

for (const crowdField of fields) {
const hubspotField = organizationMapper.getHubspotFieldName(crowdField)

if (hubspotField && organization[crowdField] !== undefined) {
hubspotCompany.properties[hubspotField] = organizationMapper.getHubspotValue(
organization,
crowdField,
)
// if hubspot domain field is mapped to a crowd field, we should ignore it
// because we handle this manually above
if (hubspotField && hubspotField !== 'domain') {
if (organization[crowdField] !== undefined) {
hubspotCompany.properties[hubspotField] = organizationMapper.getHubspotValue(
organization,
crowdField,
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,32 @@ export const batchUpdateMembers = async (

for (const crowdField of fields) {
const hubspotField = memberMapper.getHubspotFieldName(crowdField)
if (crowdField.startsWith('attributes')) {
const attributeName = crowdField.split('.')[1] || null

if (
attributeName &&
hubspotField &&
member.attributes[attributeName]?.default !== undefined
) {
hsMember.properties[hubspotField] = member.attributes[attributeName].default
// if hubspot e-mail field is mapped to a crowd field, we should ignore it because
// we handle this manually above
if (hubspotField && hubspotField !== 'email') {
if (crowdField.startsWith('attributes')) {
const attributeName = crowdField.split('.')[1] || null

if (
attributeName &&
hubspotField &&
member.attributes[attributeName]?.default !== undefined
) {
hsMember.properties[hubspotField] = member.attributes[attributeName].default
}
} else if (crowdField.startsWith('identities')) {
const identityPlatform = crowdField.split('.')[1] || null

const identityFound = member.identities.find((i) => i.platform === identityPlatform)

if (identityPlatform && hubspotField && identityFound) {
hsMember.properties[hubspotField] = identityFound.username
}
} else if (crowdField === 'organizationName') {
// send latest org of member as value
} else if (hubspotField && member[crowdField] !== undefined) {
hsMember.properties[hubspotField] = memberMapper.getHubspotValue(member, crowdField)
}
} else if (crowdField.startsWith('identities')) {
const identityPlatform = crowdField.split('.')[1] || null

const identityFound = member.identities.find((i) => i.platform === identityPlatform)

if (identityPlatform && hubspotField && identityFound) {
hsMember.properties[hubspotField] = identityFound.username
}
} else if (crowdField === 'organizationName') {
// send latest org of member as value
} else if (hubspotField && member[crowdField] !== undefined) {
hsMember.properties[hubspotField] = memberMapper.getHubspotValue(member, crowdField)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ export const batchUpdateOrganizations = async (

for (const crowdField of fields) {
const hubspotField = organizationMapper.getHubspotFieldName(crowdField)

if (hubspotField && organization[crowdField] !== undefined) {
hubspotCompany.properties[hubspotField] = organizationMapper.getHubspotValue(
organization,
crowdField,
)
// if hubspot domain field is mapped to a crowd field, we should ignore it
// because we handle this manually above
if (hubspotField && hubspotField !== 'domain') {
if (organization[crowdField] !== undefined) {
hubspotCompany.properties[hubspotField] = organizationMapper.getHubspotValue(
organization,
crowdField,
)
}
}
}

Expand Down

0 comments on commit b567dfc

Please sign in to comment.