feature/IO-3096-GlobalNotifications - Email Queue now batches per job per user
This commit is contained in:
@@ -8,13 +8,13 @@ const { getJobAssignmentType } = require("./stringHelpers");
|
||||
*/
|
||||
const populateWatchers = (data, result) => {
|
||||
data.scenarioWatchers.forEach((recipients) => {
|
||||
const { user, app, fcm, email } = recipients;
|
||||
const { user, app, fcm, email, firstName, lastName } = recipients;
|
||||
// Add user to app recipients with bodyShopId if app notification is enabled
|
||||
if (app === true) result.app.recipients.push({ user, bodyShopId: data.bodyShopId });
|
||||
// Add user to FCM recipients if FCM notification is enabled
|
||||
if (fcm === true) result.fcm.recipients.push(user);
|
||||
// Add user to email recipients if email notification is enabled
|
||||
if (email === true) result.email.recipients.push({ user });
|
||||
if (email === true) result.email.recipients.push({ user, firstName, lastName });
|
||||
});
|
||||
};
|
||||
|
||||
@@ -37,8 +37,11 @@ const alternateTransportChangedBuilder = (data) => {
|
||||
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}.`,
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
// subject: `Alternate transport for ${data?.jobRoNumber} (${data.bodyShopName}) changed to ${data.data.alt_transport || "None"}`,
|
||||
body: `The alternate transport status has been updated.`,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -66,8 +69,11 @@ const billPostedHandler = (data) => {
|
||||
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}.`,
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
// subject: `Bill posted for ${data?.jobRoNumber} (${data.bodyShopName})`,
|
||||
body: `A bill of $${data.data.clm_total} has been posted.`,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -96,8 +102,10 @@ const criticalPartsStatusChangedBuilder = (data) => {
|
||||
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"}.`,
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `The critical parts status has changed to ${data.data.queued_for_parts ? "queued" : "not queued"}.`,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -128,8 +136,10 @@ const intakeDeliveryChecklistCompletedBuilder = (data) => {
|
||||
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.`,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
jobId: data.jobId,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `The ${checklistType.charAt(0).toUpperCase() + checklistType.slice(1)} checklist has been completed.`,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -157,8 +167,10 @@ const jobAssignedToMeBuilder = (data) => {
|
||||
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}.`,
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `You have been assigned to [${getJobAssignmentType(data.scenarioFields?.[0])}]`,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -184,8 +196,10 @@ const jobsAddedToProductionBuilder = (data) => {
|
||||
recipients: []
|
||||
},
|
||||
email: {
|
||||
subject: `Job ${data?.jobRoNumber} (${data.bodyShopName}) added to production`,
|
||||
body: `Job ${data?.jobRoNumber} in ${data.bodyShopName} has been added to production.`,
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `Job has been added to production.`,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -214,8 +228,10 @@ const jobStatusChangeBuilder = (data) => {
|
||||
recipients: []
|
||||
},
|
||||
email: {
|
||||
subject: `The status of ${data?.jobRoNumber} (${data.bodyShopName}) has changed from ${data.changedFields.status.old} to ${data.data.status}`,
|
||||
body: `...`, // Placeholder indicating email body may need further customization
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `The status has changed from ${data.changedFields.status.old} to ${data.data.status}`,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -241,8 +257,10 @@ const newMediaAddedReassignedBuilder = (data) => {
|
||||
recipients: []
|
||||
},
|
||||
email: {
|
||||
subject: `New media added to ${data?.jobRoNumber} (${data.bodyShopName})`,
|
||||
body: `New media has been added to job ${data?.jobRoNumber} in ${data.bodyShopName}.`,
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `New media has been added.`,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -270,8 +288,10 @@ const newNoteAddedBuilder = (data) => {
|
||||
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}"`,
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `A new note has been added: "${data.data.text}"`,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -297,8 +317,10 @@ const newTimeTicketPostedBuilder = (data) => {
|
||||
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}.`,
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `A new time ticket has been posted.`,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -327,8 +349,11 @@ const partMarkedBackOrderedBuilder = (data) => {
|
||||
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.`,
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
// subject: `Part marked back-ordered for ${data?.jobRoNumber} (${data.bodyShopName})`,
|
||||
body: `A part has been marked as back-ordered.`,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -356,8 +381,10 @@ const paymentCollectedCompletedBuilder = (data) => {
|
||||
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}.`,
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `Payment of $${data.data.clm_total} has been collected.`,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -390,8 +417,11 @@ const scheduledDatesChangedBuilder = (data) => {
|
||||
recipients: []
|
||||
},
|
||||
email: {
|
||||
subject: `Scheduled dates updated for ${data?.jobRoNumber} (${data.bodyShopName})`,
|
||||
body: `Scheduled dates for job ${data?.jobRoNumber} in ${data.bodyShopName} have been updated.`,
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
// subject: `Scheduled dates updated for ${data?.jobRoNumber} (${data.bodyShopName})`,
|
||||
body: `Scheduled dates have been updated.`,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -419,8 +449,10 @@ const supplementImportedBuilder = (data) => {
|
||||
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}.`,
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `A supplement of $${data.data.cieca_ttl?.data?.supp_amt || 0} has been imported.`,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -449,8 +481,10 @@ const tasksUpdatedCreatedBuilder = (data) => {
|
||||
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"}.`,
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `Tasks have been ${data.isNew ? "created" : "updated"}.`,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
|
||||
Reference in New Issue
Block a user