Skip to content

Commit 3b2114a

Browse files
author
vikasrohit
authored
fixing the way update trait body is constructed
1 parent fe3b57e commit 3b2114a

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/services/TaxFormProcessorService.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ async function processMessage (message) {
2020

2121
// Get the member Onboarding Checklist traits
2222
const onboardingChecklistTraits = await helper.getMemberTraits(handle, constants.ONBOARDING_CHECKLIST_TRAIT_ID)
23+
24+
// construct the request body for saving the member traits
25+
const body = [{
26+
categoryName: constants.ONBOARDING_CHECKLIST_CATEGORY_NAME,
27+
traitId: constants.ONBOARDING_CHECKLIST_TRAIT_ID,
28+
traits: {
29+
data: []
30+
}
31+
}]
2332

2433
// Initialize the terms traits data object
2534
const termsTraitsData = {
@@ -30,23 +39,20 @@ async function processMessage (message) {
3039

3140
const traitsBodyPropertyName = _.findKey(constants.TAX_FORM_TRAIT_PROPERTY_NAME_MAP, v => _.startsWith(taxForm, v)) || constants.TAX_FORM_TRAIT_PROPERTY_NAME
3241
if (onboardingChecklistTraits.length === 0) {
33-
const body = [{
34-
categoryName: constants.ONBOARDING_CHECKLIST_CATEGORY_NAME,
35-
traitId: constants.ONBOARDING_CHECKLIST_TRAIT_ID,
36-
traits: {
37-
data: [{
38-
[traitsBodyPropertyName]: termsTraitsData
39-
}]
40-
}
41-
}]
42+
body[0].traits.data.push({
43+
[traitsBodyPropertyName]: termsTraitsData
44+
})
4245
await helper.saveMemberTraits(handle, body, true)
4346
} else {
4447
// Onboarding checklist traits already exists for the member
4548
// An update of the trait should be performed
4649

4750
// Update the currently processed terms property in the request body
48-
onboardingChecklistTraits[0].traits.data[0][traitsBodyPropertyName] = termsTraitsData
49-
await helper.saveMemberTraits(handle, onboardingChecklistTraits, false)
51+
body[0].traits.data[0] = _.cloneDeep(onboardingChecklistTraits[0].traits.data[0])
52+
53+
// Update the currently processed terms property in the request body
54+
body[0].traits.data[0][traitsBodyPropertyName] = termsTraitsData
55+
await helper.saveMemberTraits(handle, body, false)
5056
}
5157

5258
logger.info(`Successfully Processed message of taxForm ${taxForm}, userId ${message.payload.userId}, handle ${handle}`)

0 commit comments

Comments
 (0)