Website: reduce time to submit steps of the /start questionnaire. (#18721)

Related to: https://github.com/fleetdm/confidential/issues/6357

Changes:
- wrapped the `updateOrCreateContactAndAccount` helper call in
`save-questionnaire-progress` in `setImmediate()` to allow users to
progress through the form without waiting for CRM updates.
This commit is contained in:
Eric 2024-05-03 17:23:05 -05:00 committed by GitHub
parent 3846d2aca8
commit 7c3f029f78
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -208,14 +208,20 @@ module.exports = {
}//fi
// Only update CRM records if the user's psychological stage changes.
if(psychologicalStage !== userRecord.psychologicalStage){
await sails.helpers.salesforce.updateOrCreateContactAndAccount.with({
emailAddress: this.req.me.emailAddress,
firstName: this.req.me.firstName,
lastName: this.req.me.lastName,
primaryBuyingSituation: primaryBuyingSituation === 'eo-security' ? 'Endpoint operations - Security' : primaryBuyingSituation === 'eo-it' ? 'Endpoint operations - IT' : primaryBuyingSituation === 'mdm' ? 'Device management (MDM)' : primaryBuyingSituation === 'vm' ? 'Vulnerability management' : undefined,
organization: this.req.me.organization,
psychologicalStage,
if(psychologicalStage !== userRecord.psychologicalStage) {
// Use setImmediate to queue CRM updates.
// [?]: https://nodejs.org/api/timers.html#setimmediatecallback-args
require('timers').setImmediate(async ()=>{
await sails.helpers.salesforce.updateOrCreateContactAndAccount.with({
emailAddress: this.req.me.emailAddress,
firstName: this.req.me.firstName,
lastName: this.req.me.lastName,
primaryBuyingSituation: primaryBuyingSituation === 'eo-security' ? 'Endpoint operations - Security' : primaryBuyingSituation === 'eo-it' ? 'Endpoint operations - IT' : primaryBuyingSituation === 'mdm' ? 'Device management (MDM)' : primaryBuyingSituation === 'vm' ? 'Vulnerability management' : undefined,
organization: this.req.me.organization,
psychologicalStage,
}).catch((err)=>{
sails.log.warn(`When a user (email: ${this.req.me.emailAddress} submitted a step of the get started questionnaire, a Contact and Account record could not be created/updated in the CRM. Full error:`, err);
});
});
}
// TODO: send all other answers to Salesforce (when there are fields for them)