382 lines
11 KiB
JavaScript
382 lines
11 KiB
JavaScript
const { getJobAssignmentType } = require("./stringHelpers");
|
|
|
|
const populateWatchers = (data, result) => {
|
|
data.scenarioWatchers.forEach((recipients) => {
|
|
const { user, app, fcm, email } = recipients;
|
|
if (app === true) result.app.recipients.push({ user, bodyShopId: data.bodyShopId });
|
|
if (fcm === true) result.fcm.recipients.push(user);
|
|
if (email === true) result.email.recipients.push({ user });
|
|
});
|
|
};
|
|
|
|
const alternateTransportChangedBuilder = (data) => {
|
|
const result = {
|
|
app: {
|
|
jobId: data.jobId,
|
|
bodyShopId: data.bodyShopId,
|
|
key: "notifications.job.alternateTransportChanged",
|
|
variables: {
|
|
alternateTransport: data.data.alt_transport,
|
|
oldAlternateTransport: data.changedFields.alt_transport?.old
|
|
},
|
|
recipients: []
|
|
},
|
|
email: {
|
|
subject: `Alternate transport for ${data?.jobRoNumber} (${data.bodyShopName}) changed to ${data.data.alt_transport || "None"}`,
|
|
body: `The alternate transport status has been updated for job ${data?.jobRoNumber} in ${data.bodyShopName}.`,
|
|
recipients: []
|
|
},
|
|
fcm: { recipients: [] }
|
|
};
|
|
|
|
populateWatchers(data, result);
|
|
return result;
|
|
};
|
|
|
|
const billPostedHandler = (data) => {
|
|
const result = {
|
|
app: {
|
|
jobId: data.jobId,
|
|
bodyShopId: data.bodyShopId,
|
|
key: "notifications.job.billPosted",
|
|
variables: {
|
|
clmTotal: data.data.clm_total
|
|
},
|
|
recipients: []
|
|
},
|
|
email: {
|
|
subject: `Bill posted for ${data?.jobRoNumber} (${data.bodyShopName})`,
|
|
body: `A bill of $${data.data.clm_total} has been posted for job ${data?.jobRoNumber} in ${data.bodyShopName}.`,
|
|
recipients: []
|
|
},
|
|
fcm: { recipients: [] }
|
|
};
|
|
|
|
populateWatchers(data, result);
|
|
return result;
|
|
};
|
|
|
|
const criticalPartsStatusChangedBuilder = (data) => {
|
|
const result = {
|
|
app: {
|
|
jobId: data.jobId,
|
|
bodyShopId: data.bodyShopId,
|
|
key: "notifications.job.criticalPartsStatusChanged",
|
|
variables: {
|
|
queuedForParts: data.data.queued_for_parts,
|
|
oldQueuedForParts: data.changedFields.queued_for_parts?.old
|
|
},
|
|
recipients: []
|
|
},
|
|
email: {
|
|
subject: `Critical parts status for ${data?.jobRoNumber} (${data.bodyShopName}) updated`,
|
|
body: `The critical parts status for job ${data?.jobRoNumber} in ${data.bodyShopName} has changed to ${data.data.queued_for_parts ? "queued" : "not queued"}.`,
|
|
recipients: []
|
|
},
|
|
fcm: { recipients: [] }
|
|
};
|
|
|
|
populateWatchers(data, result);
|
|
return result;
|
|
};
|
|
|
|
const intakeDeliveryChecklistCompletedBuilder = (data) => {
|
|
const checklistType = data.changedFields.intakechecklist ? "intake" : "delivery";
|
|
const result = {
|
|
app: {
|
|
jobId: data.jobId,
|
|
bodyShopId: data.bodyShopId,
|
|
key: "notifications.job.checklistCompleted",
|
|
variables: {
|
|
checklistType,
|
|
completed: true
|
|
},
|
|
recipients: []
|
|
},
|
|
email: {
|
|
subject: `${checklistType.charAt(0).toUpperCase() + checklistType.slice(1)} checklist completed for ${data?.jobRoNumber} (${data.bodyShopName})`,
|
|
body: `The ${checklistType} checklist for job ${data?.jobRoNumber} in ${data.bodyShopName} has been completed.`,
|
|
recipients: []
|
|
},
|
|
fcm: { recipients: [] }
|
|
};
|
|
|
|
populateWatchers(data, result);
|
|
return result;
|
|
};
|
|
|
|
const jobAssignedToMeBuilder = (data) => {
|
|
const result = {
|
|
app: {
|
|
jobId: data.jobId,
|
|
bodyShopId: data.bodyShopId,
|
|
key: "notifications.job.assigned",
|
|
variables: {
|
|
type: data.scenarioFields?.[0]
|
|
},
|
|
recipients: []
|
|
},
|
|
email: {
|
|
subject: `You have been assigned to [${getJobAssignmentType(data.scenarioFields?.[0])}] on ${data?.jobRoNumber} in ${data.bodyShopName}`,
|
|
body: `Hello, a new job has been assigned to you in ${data.bodyShopName}.`,
|
|
recipients: []
|
|
},
|
|
fcm: { recipients: [] }
|
|
};
|
|
|
|
populateWatchers(data, result);
|
|
return result;
|
|
};
|
|
|
|
const jobsAddedToProductionBuilder = (data) => {
|
|
const result = {
|
|
app: {
|
|
jobId: data.jobId,
|
|
bodyShopId: data.bodyShopId,
|
|
key: "notifications.job.addedToProduction",
|
|
variables: {},
|
|
recipients: []
|
|
},
|
|
email: {
|
|
subject: `Job ${data?.jobRoNumber} (${data.bodyShopName}) added to production`,
|
|
body: `Job ${data?.jobRoNumber} in ${data.bodyShopName} has been added to production.`,
|
|
recipients: []
|
|
},
|
|
fcm: { recipients: [] }
|
|
};
|
|
|
|
populateWatchers(data, result);
|
|
return result;
|
|
};
|
|
|
|
// Verified
|
|
const jobStatusChangeBuilder = (data) => {
|
|
const result = {
|
|
app: {
|
|
jobId: data.jobId,
|
|
bodyShopId: data.bodyShopId,
|
|
key: "notifications.job.statusChanged",
|
|
variables: {
|
|
status: data.data.status,
|
|
oldStatus: data.changedFields.status.old
|
|
},
|
|
recipients: []
|
|
},
|
|
email: {
|
|
subject: `The status of ${data?.jobRoNumber} (${data.bodyShopName}) has changed from ${data.changedFields.status.old} to ${data.data.status}`,
|
|
body: `...`,
|
|
recipients: []
|
|
},
|
|
fcm: { recipients: [] }
|
|
};
|
|
|
|
populateWatchers(data, result);
|
|
return result;
|
|
};
|
|
|
|
const newMediaAddedReassignedBuilder = (data) => {
|
|
const result = {
|
|
app: {
|
|
jobId: data.jobId,
|
|
bodyShopId: data.bodyShopId,
|
|
key: "notifications.job.newMediaAdded",
|
|
variables: {},
|
|
recipients: []
|
|
},
|
|
email: {
|
|
subject: `New media added to ${data?.jobRoNumber} (${data.bodyShopName})`,
|
|
body: `New media has been added to job ${data?.jobRoNumber} in ${data.bodyShopName}.`,
|
|
recipients: []
|
|
},
|
|
fcm: { recipients: [] }
|
|
};
|
|
|
|
populateWatchers(data, result);
|
|
return result;
|
|
};
|
|
|
|
// Verified
|
|
const newNoteAddedBuilder = (data) => {
|
|
const result = {
|
|
app: {
|
|
jobId: data.jobId,
|
|
bodyShopId: data.bodyShopId,
|
|
key: "notifications.job.newNoteAdded",
|
|
variables: {
|
|
text: data.data.text
|
|
},
|
|
recipients: []
|
|
},
|
|
email: {
|
|
subject: `New note added to ${data?.jobRoNumber} (${data.bodyShopName})`,
|
|
body: `A new note has been added to job ${data?.jobRoNumber} in ${data.bodyShopName}: "${data.data.text}"`,
|
|
recipients: []
|
|
},
|
|
fcm: { recipients: [] }
|
|
};
|
|
|
|
populateWatchers(data, result);
|
|
return result;
|
|
};
|
|
|
|
const newTimeTicketPostedBuilder = (data) => {
|
|
const result = {
|
|
app: {
|
|
jobId: data.jobId,
|
|
bodyShopId: data.bodyShopId,
|
|
key: "notifications.job.newTimeTicketPosted",
|
|
variables: {},
|
|
recipients: []
|
|
},
|
|
email: {
|
|
subject: `New time ticket posted for ${data?.jobRoNumber} (${data.bodyShopName})`,
|
|
body: `A new time ticket has been posted for job ${data?.jobRoNumber} in ${data.bodyShopName}.`,
|
|
recipients: []
|
|
},
|
|
fcm: { recipients: [] }
|
|
};
|
|
|
|
populateWatchers(data, result);
|
|
return result;
|
|
};
|
|
|
|
const partMarkedBackOrderedBuilder = (data) => {
|
|
const result = {
|
|
app: {
|
|
jobId: data.jobId,
|
|
bodyShopId: data.bodyShopId,
|
|
key: "notifications.job.partBackOrdered",
|
|
variables: {
|
|
queuedForParts: data.data.queued_for_parts,
|
|
oldQueuedForParts: data.changedFields.queued_for_parts?.old
|
|
},
|
|
recipients: []
|
|
},
|
|
email: {
|
|
subject: `Part marked back-ordered for ${data?.jobRoNumber} (${data.bodyShopName})`,
|
|
body: `A part for job ${data?.jobRoNumber} in ${data.bodyShopName} has been marked as back-ordered.`,
|
|
recipients: []
|
|
},
|
|
fcm: { recipients: [] }
|
|
};
|
|
|
|
populateWatchers(data, result);
|
|
return result;
|
|
};
|
|
|
|
const paymentCollectedCompletedBuilder = (data) => {
|
|
const result = {
|
|
app: {
|
|
jobId: data.jobId,
|
|
bodyShopId: data.bodyShopId,
|
|
key: "notifications.job.paymentCollected",
|
|
variables: {
|
|
clmTotal: data.data.clm_total
|
|
},
|
|
recipients: []
|
|
},
|
|
email: {
|
|
subject: `Payment collected for ${data?.jobRoNumber} (${data.bodyShopName})`,
|
|
body: `Payment of $${data.data.clm_total} has been collected for job ${data?.jobRoNumber} in ${data.bodyShopName}.`,
|
|
recipients: []
|
|
},
|
|
fcm: { recipients: [] }
|
|
};
|
|
|
|
populateWatchers(data, result);
|
|
return result;
|
|
};
|
|
|
|
const scheduledDatesChangedBuilder = (data) => {
|
|
const result = {
|
|
app: {
|
|
jobId: data.jobId,
|
|
bodyShopId: data.bodyShopId,
|
|
key: "notifications.job.scheduledDatesChanged",
|
|
variables: {
|
|
scheduledIn: data.data.scheduled_in,
|
|
oldScheduledIn: data.changedFields.scheduled_in?.old,
|
|
scheduledCompletion: data.data.scheduled_completion,
|
|
oldScheduledCompletion: data.changedFields.scheduled_completion?.old,
|
|
scheduledDelivery: data.data.scheduled_delivery,
|
|
oldScheduledDelivery: data.changedFields.scheduled_delivery?.old
|
|
},
|
|
recipients: []
|
|
},
|
|
email: {
|
|
subject: `Scheduled dates updated for ${data?.jobRoNumber} (${data.bodyShopName})`,
|
|
body: `Scheduled dates for job ${data?.jobRoNumber} in ${data.bodyShopName} have been updated.`,
|
|
recipients: []
|
|
},
|
|
fcm: { recipients: [] }
|
|
};
|
|
|
|
populateWatchers(data, result);
|
|
return result;
|
|
};
|
|
|
|
const supplementImportedBuilder = (data) => {
|
|
const result = {
|
|
app: {
|
|
jobId: data.jobId,
|
|
bodyShopId: data.bodyShopId,
|
|
key: "notifications.job.supplementImported",
|
|
variables: {
|
|
suppAmt: data.data.cieca_ttl?.data?.supp_amt
|
|
},
|
|
recipients: []
|
|
},
|
|
email: {
|
|
subject: `Supplement imported for ${data?.jobRoNumber} (${data.bodyShopName})`,
|
|
body: `A supplement of $${data.data.cieca_ttl?.data?.supp_amt || 0} has been imported for job ${data?.jobRoNumber} in ${data.bodyShopName}.`,
|
|
recipients: []
|
|
},
|
|
fcm: { recipients: [] }
|
|
};
|
|
|
|
populateWatchers(data, result);
|
|
return result;
|
|
};
|
|
|
|
const tasksUpdatedCreatedBuilder = (data) => {
|
|
const result = {
|
|
app: {
|
|
jobId: data.jobId,
|
|
bodyShopId: data.bodyShopId,
|
|
key: "notifications.job.tasksUpdated",
|
|
variables: {
|
|
type: data.isNew ? "created" : "updated",
|
|
roNumber: data.jobRoNumber
|
|
},
|
|
recipients: []
|
|
},
|
|
email: {
|
|
subject: `Tasks ${data.isNew ? "created" : "updated"} for ${data?.jobRoNumber} (${data.bodyShopName})`,
|
|
body: `Tasks for job ${data?.jobRoNumber} in ${data.bodyShopName} have been ${data.isNew ? "created" : "updated"}.`,
|
|
recipients: []
|
|
},
|
|
fcm: { recipients: [] }
|
|
};
|
|
|
|
populateWatchers(data, result);
|
|
return result;
|
|
};
|
|
|
|
module.exports = {
|
|
alternateTransportChangedBuilder,
|
|
billPostedHandler,
|
|
criticalPartsStatusChangedBuilder,
|
|
intakeDeliveryChecklistCompletedBuilder,
|
|
jobAssignedToMeBuilder,
|
|
jobsAddedToProductionBuilder,
|
|
jobStatusChangeBuilder,
|
|
newMediaAddedReassignedBuilder,
|
|
newNoteAddedBuilder,
|
|
newTimeTicketPostedBuilder,
|
|
partMarkedBackOrderedBuilder,
|
|
paymentCollectedCompletedBuilder,
|
|
scheduledDatesChangedBuilder,
|
|
supplementImportedBuilder,
|
|
tasksUpdatedCreatedBuilder
|
|
};
|