diff --git a/server/data/kaizen.js b/server/data/kaizen.js index 8b95044e7..ffe87de80 100644 --- a/server/data/kaizen.js +++ b/server/data/kaizen.js @@ -264,29 +264,30 @@ const CreateRepairOrderTag = (job, errorCallback) => { }${job.est_ct_fn ? job.est_ct_fn : ""}` }, Dates: { - DateEstimated: (job.date_estimated && moment(job.date_estimated).format(DateFormat)) || "", - DateOpened: (job.date_opened && moment(job.date_opened).format(DateFormat)) || "", - DateScheduled: - (job.scheduled_in && moment(job.scheduled_in).tz(job.bodyshop.timezone).format(DateFormat)) || "", - DateArrived: (job.actual_in && moment(job.actual_in).tz(job.bodyshop.timezone).format(DateFormat)) || "", + DateEstimated: job.date_estimated ? moment(job.date_estimated).format(DateFormat) : "", + DateOpened: job.date_open ? moment(job.date_open).tz(job.bodyshop.timezone).format(DateFormat) : "", + DateScheduled: job.scheduled_in ? moment(job.scheduled_in).tz(job.bodyshop.timezone).format(DateFormat) : "", + DateArrived: job.actual_in ? moment(job.actual_in).tz(job.bodyshop.timezone).format(DateFormat) : "", DateStart: job.date_repairstarted - ? (job.date_repairstarted && moment(job.date_repairstarted).tz(job.bodyshop.timezone).format(DateFormat)) || - "" - : (job.actual_in && moment(job.actual_in).tz(job.bodyshop.timezone).format(DateFormat)) || "", - DateScheduledCompletion: - (job.scheduled_completion && moment(job.scheduled_completion).tz(job.bodyshop.timezone).format(DateFormat)) || - "", - DateCompleted: - (job.actual_completion && moment(job.actual_completion).tz(job.bodyshop.timezone).format(DateFormat)) || "", - DateScheduledDelivery: - (job.scheduled_delivery && moment(job.scheduled_delivery).tz(job.bodyshop.timezone).format(DateFormat)) || "", - DateDelivered: - (job.actual_delivery && moment(job.actual_delivery).tz(job.bodyshop.timezone).format(DateFormat)) || "", - DateInvoiced: - (job.date_invoiced && moment(job.date_invoiced).tz(job.bodyshop.timezone).format(DateFormat)) || "", - DateExported: - (job.date_exported && moment(job.date_exported).tz(job.bodyshop.timezone).format(DateFormat)) || "", - DateVoid: (job.date_void && moment(job.date_void).tz(job.bodyshop.timezone).format(DateFormat)) || "" + ? moment(job.date_repairstarted).tz(job.bodyshop.timezone).format(DateFormat) + : job.actual_in + ? moment(job.actual_in).tz(job.bodyshop.timezone).format(DateFormat) + : "", + DateScheduledCompletion: job.scheduled_completion + ? moment(job.scheduled_completion).tz(job.bodyshop.timezone).format(DateFormat) + : "", + DateCompleted: job.actual_completion + ? moment(job.actual_completion).tz(job.bodyshop.timezone).format(DateFormat) + : "", + DateScheduledDelivery: job.scheduled_delivery + ? moment(job.scheduled_delivery).tz(job.bodyshop.timezone).format(DateFormat) + : "", + DateDelivered: job.actual_delivery + ? moment(job.actual_delivery).tz(job.bodyshop.timezone).format(DateFormat) + : "", + DateInvoiced: job.date_invoiced ? moment(job.date_invoiced).tz(job.bodyshop.timezone).format(DateFormat) : "", + DateExported: job.date_exported ? moment(job.date_exported).tz(job.bodyshop.timezone).format(DateFormat) : "", + DateVoid: job.date_void ? moment(job.date_void).tz(job.bodyshop.timezone).format(DateFormat) : "" }, JobLineDetails: (function () { const joblineSource = Array.isArray(job.joblines) ? job.joblines : job.joblines ? [job.joblines] : []; diff --git a/server/fortellis/fortellis-helpers.js b/server/fortellis/fortellis-helpers.js index f54e375b8..087dc3d16 100644 --- a/server/fortellis/fortellis-helpers.js +++ b/server/fortellis/fortellis-helpers.js @@ -235,18 +235,6 @@ async function MakeFortellisCall({ // jobid: socket?.recordid // }); - if (result.data.checkStatusAfterSeconds) { - return DelayedCallback({ - delayMeta: result.data, - access_token, - SubscriptionID: SubscriptionMeta.subscriptionId, - ReqId, - departmentIds: DepartmentId - }); - } - - - logger.log( "fortellis-log-event-json", "DEBUG", @@ -261,6 +249,18 @@ async function MakeFortellisCall({ }, ); + if (result.data.checkStatusAfterSeconds) { + return DelayedCallback({ + delayMeta: result.data, + access_token, + SubscriptionID: SubscriptionMeta.subscriptionId, + ReqId, + departmentIds: DepartmentId, + jobid, + socket + }); + } + return result.data; } catch (error) { const errorDetails = { @@ -310,7 +310,7 @@ async function MakeFortellisCall({ //Some Fortellis calls return a batch result that isn't ready immediately. //This function will check the status of the call and wait until it is ready. //It will try 5 times before giving up. -async function DelayedCallback({ delayMeta, access_token, SubscriptionID, ReqId, departmentIds }) { +async function DelayedCallback({ delayMeta, access_token, SubscriptionID, ReqId, departmentIds, jobid, socket }) { for (let index = 0; index < 5; index++) { await sleep(delayMeta.checkStatusAfterSeconds * 1000); //Check to see if the call is ready. @@ -334,6 +334,19 @@ async function DelayedCallback({ delayMeta, access_token, SubscriptionID, ReqId, //"Department-Id": departmentIds[0].id } }); + logger.log( + "fortellis-log-event-json-DelayedCallback", + "DEBUG", + socket?.user?.email, + jobid, + { + requestcurl: batchResult.config.curlCommand, + reqid: batchResult.config.headers["Request-Id"] || null, + subscriptionId: batchResult.config.headers["Subscription-Id"] || null, + resultdata: batchResult.data, + resultStatus: batchResult.status + }, + ); // await writeFortellisLogToFile({ // timestamp: new Date().toISOString(), // reqId: ReqId,