Skip to content

Commit 5e9dccc

Browse files
committed
fix: update trait data format
1 parent f98c9c1 commit 5e9dccc

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

src/common/helper.js

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ async function updateRecord (record) {
113113
}
114114

115115
/**
116-
*
116+
* Get trait onboarding_checklist from member Api
117+
* @param {string} handle the member handle
118+
* @returns {promise} the result
117119
*/
118120
async function getOnboardingChecklist (handle, token) {
119121
const url = `${config.MEMBERS_API_URL}/${handle}/traits?traitIds=onboarding_checklist`
@@ -128,39 +130,48 @@ async function getOnboardingChecklist (handle, token) {
128130
if (responseObject.length > 0) {
129131
return responseObject[0].traits.data
130132
}
131-
} catch (err) {}
133+
} catch (err) { }
132134

133135
return []
134136
}
135137

138+
/**
139+
* update trait onboarding_checklist to indicate to consumers that showing the user
140+
* identified by handle is not required
141+
*
142+
* @param {string} handle the handle of the member
143+
* @param {string} message the skip reason
144+
* @returns {promise}
145+
*/
136146
async function addSkipOnboardingInOnboardingChecklist (handle, message) {
137147
const token = await getM2MToken()
138148

139149
const existingOnboardingCheckilst = await getOnboardingChecklist(handle, token)
140150
const shouldCreate = existingOnboardingCheckilst.length === 0
141151

142-
const skipOnboardingIndex = _.findIndex(existingOnboardingCheckilst, data => {
143-
if (data['skip_onboarding'] != null) {
144-
return true
145-
}
146-
147-
return false
148-
})
149-
150-
const skipOnboardingData = {
151-
skip_onboarding: {
152-
value: true,
152+
const onboardingWizardIndex = _.findIndex(existingOnboardingCheckilst, data => data['onboarding_wizard'] != null)
153+
const onboardingWizardData = {
154+
onboarding_wizard: {
155+
skip: true,
153156
date: new Date().getTime(),
154-
message
157+
metadata: {
158+
skipReason: message
159+
},
160+
status: 'pending_at_user'
155161
}
156162
}
157163

158164
let traitData = existingOnboardingCheckilst
159165

160-
if (skipOnboardingIndex === -1) {
161-
traitData.push(skipOnboardingData)
166+
if (onboardingWizardIndex === -1) {
167+
traitData.push(onboardingWizardData)
162168
} else {
163-
traitData[skipOnboardingIndex] = skipOnboardingData
169+
// copy over existing status
170+
if (traitData[onboardingWizardIndex].onboarding_wizard.status != null) {
171+
onboardingWizardData.onboarding_wizard.status = traitData[onboardingWizardIndex].onboarding_wizard.status
172+
}
173+
174+
traitData[onboardingWizardIndex] = onboardingWizardData
164175
}
165176

166177
const payload = [{
@@ -180,14 +191,14 @@ async function addSkipOnboardingInOnboardingChecklist (handle, message) {
180191

181192
try {
182193
if (shouldCreate) {
183-
logger.info(`Creating onboarding_checklist with skip_onboarding for user with handle ${handle}.`)
194+
logger.info(`Creating onboarding_checklist with onboarding_wizard for user with handle ${handle}.`)
184195
await axios.post(url, payload, requestConfig)
185196
} else {
186-
logger.info(`Updating onboarding_checklist to add skip_onboarding for user with handle ${handle}.`)
197+
logger.info(`Updating onboarding_checklist to add onboarding_wizard for user with handle ${handle}.`)
187198
await axios.put(url, payload, requestConfig)
188199
}
189200
} catch (err) {
190-
logger.error(`Failed to set skip_onboarding in onboarding_checklist for user with handle ${handle}. Failed with error ${JSON.stringify(err)}`)
201+
logger.error(`Failed to set onboarding_wizard in onboarding_checklist for user with handle ${handle}. Failed with error ${JSON.stringify(err)}`)
191202
}
192203
}
193204

0 commit comments

Comments
 (0)