feature/IO-3096-GlobalNotifications - Package updates, prepare scenario builder for app notifications, redo header to have right aligned items.
This commit is contained in:
@@ -9,29 +9,25 @@ const { getJobAssignmentType } = require("./stringHelpers");
|
||||
const populateWatchers = (data, result) => {
|
||||
data.scenarioWatchers.forEach((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, firstName, lastName });
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Builds notification data for changes to alternate transport.
|
||||
*
|
||||
* @param {Object} data - The data object containing job details and alternate transport changes.
|
||||
* @returns {Object} Notification data structured for app, email, and FCM channels.
|
||||
*/
|
||||
const alternateTransportChangedBuilder = (data) => {
|
||||
const body = `The alternate transport status has been updated from ${data?.changedFields?.altTransport?.old}.`;
|
||||
const result = {
|
||||
app: {
|
||||
jobId: data.jobId,
|
||||
bodyShopId: data.bodyShopId,
|
||||
key: "notifications.job.alternateTransportChanged",
|
||||
body, // Same as email body
|
||||
variables: {
|
||||
alternateTransport: data.data.alt_transport,
|
||||
alternateTransport: data.changedFields.alt_transport?.new,
|
||||
oldAlternateTransport: data.changedFields.alt_transport?.old
|
||||
},
|
||||
recipients: []
|
||||
@@ -40,8 +36,7 @@ const alternateTransportChangedBuilder = (data) => {
|
||||
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.`,
|
||||
body,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -53,16 +48,15 @@ const alternateTransportChangedBuilder = (data) => {
|
||||
|
||||
/**
|
||||
* Builds notification data for bill posted events.
|
||||
*
|
||||
* @param {Object} data - The data object containing job and billing details.
|
||||
* @returns {Object} Notification data structured for app, email, and FCM channels.
|
||||
*/
|
||||
const billPostedHandler = (data) => {
|
||||
const body = `A bill of $${data.data.clm_total} has been posted.`;
|
||||
const result = {
|
||||
app: {
|
||||
jobId: data.jobId,
|
||||
bodyShopId: data.bodyShopId,
|
||||
key: "notifications.job.billPosted",
|
||||
body,
|
||||
variables: {
|
||||
clmTotal: data.data.clm_total
|
||||
},
|
||||
@@ -72,8 +66,7 @@ const billPostedHandler = (data) => {
|
||||
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.`,
|
||||
body,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -85,16 +78,15 @@ const billPostedHandler = (data) => {
|
||||
|
||||
/**
|
||||
* Builds notification data for changes to critical parts status.
|
||||
*
|
||||
* @param {Object} data - The data object containing job details and critical parts status changes.
|
||||
* @returns {Object} Notification data structured for app, email, and FCM channels.
|
||||
*/
|
||||
const criticalPartsStatusChangedBuilder = (data) => {
|
||||
const body = `The critical parts status has changed to ${data.data.queued_for_parts ? "queued" : "not queued"}.`;
|
||||
const result = {
|
||||
app: {
|
||||
jobId: data.jobId,
|
||||
bodyShopId: data.bodyShopId,
|
||||
key: "notifications.job.criticalPartsStatusChanged",
|
||||
body,
|
||||
variables: {
|
||||
queuedForParts: data.data.queued_for_parts,
|
||||
oldQueuedForParts: data.changedFields.queued_for_parts?.old
|
||||
@@ -105,7 +97,7 @@ const criticalPartsStatusChangedBuilder = (data) => {
|
||||
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"}.`,
|
||||
body,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -117,18 +109,16 @@ const criticalPartsStatusChangedBuilder = (data) => {
|
||||
|
||||
/**
|
||||
* Builds notification data for completed intake or delivery checklists.
|
||||
*
|
||||
* @param {Object} data - The data object containing job details and checklist changes.
|
||||
* @returns {Object} Notification data structured for app, email, and FCM channels.
|
||||
*/
|
||||
const intakeDeliveryChecklistCompletedBuilder = (data) => {
|
||||
// Determine checklist type based on which field was changed
|
||||
const checklistType = data.changedFields.intakechecklist ? "intake" : "delivery";
|
||||
const body = `The ${checklistType.charAt(0).toUpperCase() + checklistType.slice(1)} checklist has been completed.`;
|
||||
const result = {
|
||||
app: {
|
||||
jobId: data.jobId,
|
||||
bodyShopId: data.bodyShopId,
|
||||
key: "notifications.job.checklistCompleted",
|
||||
body,
|
||||
variables: {
|
||||
checklistType,
|
||||
completed: true
|
||||
@@ -136,10 +126,10 @@ const intakeDeliveryChecklistCompletedBuilder = (data) => {
|
||||
recipients: []
|
||||
},
|
||||
email: {
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `The ${checklistType.charAt(0).toUpperCase() + checklistType.slice(1)} checklist has been completed.`,
|
||||
body,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -151,16 +141,15 @@ const intakeDeliveryChecklistCompletedBuilder = (data) => {
|
||||
|
||||
/**
|
||||
* Builds notification data for job assignment events.
|
||||
*
|
||||
* @param {Object} data - The data object containing job details and scenario fields.
|
||||
* @returns {Object} Notification data structured for app, email, and FCM channels.
|
||||
*/
|
||||
const jobAssignedToMeBuilder = (data) => {
|
||||
const body = `You have been assigned to [${getJobAssignmentType(data.scenarioFields?.[0])}]`;
|
||||
const result = {
|
||||
app: {
|
||||
jobId: data.jobId,
|
||||
bodyShopId: data.bodyShopId,
|
||||
key: "notifications.job.assigned",
|
||||
body,
|
||||
variables: {
|
||||
type: data.scenarioFields?.[0]
|
||||
},
|
||||
@@ -170,7 +159,7 @@ const jobAssignedToMeBuilder = (data) => {
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `You have been assigned to [${getJobAssignmentType(data.scenarioFields?.[0])}]`,
|
||||
body,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -182,16 +171,15 @@ const jobAssignedToMeBuilder = (data) => {
|
||||
|
||||
/**
|
||||
* Builds notification data for jobs added to production.
|
||||
*
|
||||
* @param {Object} data - The data object containing job details.
|
||||
* @returns {Object} Notification data structured for app, email, and FCM channels.
|
||||
*/
|
||||
const jobsAddedToProductionBuilder = (data) => {
|
||||
const body = `Job has been added to production.`;
|
||||
const result = {
|
||||
app: {
|
||||
jobId: data.jobId,
|
||||
bodyShopId: data.bodyShopId,
|
||||
key: "notifications.job.addedToProduction",
|
||||
body,
|
||||
variables: {},
|
||||
recipients: []
|
||||
},
|
||||
@@ -199,7 +187,7 @@ const jobsAddedToProductionBuilder = (data) => {
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `Job has been added to production.`,
|
||||
body,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -211,18 +199,17 @@ const jobsAddedToProductionBuilder = (data) => {
|
||||
|
||||
/**
|
||||
* Builds notification data for job status changes.
|
||||
*
|
||||
* @param {Object} data - The data object containing job details and status changes.
|
||||
* @returns {Object} Notification data structured for app, email, and FCM channels.
|
||||
*/
|
||||
const jobStatusChangeBuilder = (data) => {
|
||||
const body = `The status has changed from ${data.changedFields.status.old} to ${data.changedFields.status.new}`;
|
||||
const result = {
|
||||
app: {
|
||||
jobId: data.jobId,
|
||||
bodyShopId: data.bodyShopId,
|
||||
key: "notifications.job.statusChanged",
|
||||
body,
|
||||
variables: {
|
||||
status: data.data.status,
|
||||
status: data.changedFields.status.new,
|
||||
oldStatus: data.changedFields.status.old
|
||||
},
|
||||
recipients: []
|
||||
@@ -231,7 +218,7 @@ const jobStatusChangeBuilder = (data) => {
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `The status has changed from ${data.changedFields.status.old} to ${data.data.status}`,
|
||||
body,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -243,16 +230,15 @@ const jobStatusChangeBuilder = (data) => {
|
||||
|
||||
/**
|
||||
* Builds notification data for new media added or reassigned events.
|
||||
*
|
||||
* @param {Object} data - The data object containing job details.
|
||||
* @returns {Object} Notification data structured for app, email, and FCM channels.
|
||||
*/
|
||||
const newMediaAddedReassignedBuilder = (data) => {
|
||||
const body = `New media has been added.`;
|
||||
const result = {
|
||||
app: {
|
||||
jobId: data.jobId,
|
||||
bodyShopId: data.bodyShopId,
|
||||
key: "notifications.job.newMediaAdded",
|
||||
body,
|
||||
variables: {},
|
||||
recipients: []
|
||||
},
|
||||
@@ -260,7 +246,7 @@ const newMediaAddedReassignedBuilder = (data) => {
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `New media has been added.`,
|
||||
body,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -272,16 +258,15 @@ const newMediaAddedReassignedBuilder = (data) => {
|
||||
|
||||
/**
|
||||
* Builds notification data for new notes added to a job.
|
||||
*
|
||||
* @param {Object} data - The data object containing job details and note text.
|
||||
* @returns {Object} Notification data structured for app, email, and FCM channels.
|
||||
*/
|
||||
const newNoteAddedBuilder = (data) => {
|
||||
const body = `A new note has been added: "${data.data.text}"`;
|
||||
const result = {
|
||||
app: {
|
||||
jobId: data.jobId,
|
||||
bodyShopId: data.bodyShopId,
|
||||
key: "notifications.job.newNoteAdded",
|
||||
body,
|
||||
variables: {
|
||||
text: data.data.text
|
||||
},
|
||||
@@ -291,7 +276,7 @@ const newNoteAddedBuilder = (data) => {
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `A new note has been added: "${data.data.text}"`,
|
||||
body,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -303,16 +288,15 @@ const newNoteAddedBuilder = (data) => {
|
||||
|
||||
/**
|
||||
* Builds notification data for new time tickets posted.
|
||||
*
|
||||
* @param {Object} data - The data object containing job details.
|
||||
* @returns {Object} Notification data structured for app, email, and FCM channels.
|
||||
*/
|
||||
const newTimeTicketPostedBuilder = (data) => {
|
||||
const body = `A new time ticket has been posted.`;
|
||||
const result = {
|
||||
app: {
|
||||
jobId: data.jobId,
|
||||
bodyShopId: data.bodyShopId,
|
||||
key: "notifications.job.newTimeTicketPosted",
|
||||
body,
|
||||
variables: {},
|
||||
recipients: []
|
||||
},
|
||||
@@ -320,7 +304,7 @@ const newTimeTicketPostedBuilder = (data) => {
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `A new time ticket has been posted.`,
|
||||
body,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -332,18 +316,17 @@ const newTimeTicketPostedBuilder = (data) => {
|
||||
|
||||
/**
|
||||
* Builds notification data for parts marked as back-ordered.
|
||||
*
|
||||
* @param {Object} data - The data object containing job details and parts status changes.
|
||||
* @returns {Object} Notification data structured for app, email, and FCM channels.
|
||||
*/
|
||||
const partMarkedBackOrderedBuilder = (data) => {
|
||||
const body = `A part has been marked as back-ordered.`;
|
||||
const result = {
|
||||
app: {
|
||||
jobId: data.jobId,
|
||||
bodyShopId: data.bodyShopId,
|
||||
key: "notifications.job.partBackOrdered",
|
||||
body,
|
||||
variables: {
|
||||
queuedForParts: data.data.queued_for_parts,
|
||||
queuedForParts: data.changedFields.queued_for_parts?.new,
|
||||
oldQueuedForParts: data.changedFields.queued_for_parts?.old
|
||||
},
|
||||
recipients: []
|
||||
@@ -352,8 +335,7 @@ const partMarkedBackOrderedBuilder = (data) => {
|
||||
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.`,
|
||||
body,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -365,16 +347,15 @@ const partMarkedBackOrderedBuilder = (data) => {
|
||||
|
||||
/**
|
||||
* Builds notification data for payment collection events.
|
||||
*
|
||||
* @param {Object} data - The data object containing job and payment details.
|
||||
* @returns {Object} Notification data structured for app, email, and FCM channels.
|
||||
*/
|
||||
const paymentCollectedCompletedBuilder = (data) => {
|
||||
const body = `Payment of $${data.data.clm_total} has been collected.`;
|
||||
const result = {
|
||||
app: {
|
||||
jobId: data.jobId,
|
||||
bodyShopId: data.bodyShopId,
|
||||
key: "notifications.job.paymentCollected",
|
||||
body,
|
||||
variables: {
|
||||
clmTotal: data.data.clm_total
|
||||
},
|
||||
@@ -384,7 +365,7 @@ const paymentCollectedCompletedBuilder = (data) => {
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `Payment of $${data.data.clm_total} has been collected.`,
|
||||
body,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -396,22 +377,21 @@ const paymentCollectedCompletedBuilder = (data) => {
|
||||
|
||||
/**
|
||||
* Builds notification data for changes to scheduled dates.
|
||||
*
|
||||
* @param {Object} data - The data object containing job details and scheduling changes.
|
||||
* @returns {Object} Notification data structured for app, email, and FCM channels.
|
||||
*/
|
||||
const scheduledDatesChangedBuilder = (data) => {
|
||||
const body = `Scheduled dates have been updated.`;
|
||||
const result = {
|
||||
app: {
|
||||
jobId: data.jobId,
|
||||
bodyShopId: data.bodyShopId,
|
||||
key: "notifications.job.scheduledDatesChanged",
|
||||
body,
|
||||
variables: {
|
||||
scheduledIn: data.data.scheduled_in,
|
||||
scheduledIn: data.changedFields.scheduled_in?.new,
|
||||
oldScheduledIn: data.changedFields.scheduled_in?.old,
|
||||
scheduledCompletion: data.data.scheduled_completion,
|
||||
scheduledCompletion: data.changedFields.scheduled_completion?.new,
|
||||
oldScheduledCompletion: data.changedFields.scheduled_completion?.old,
|
||||
scheduledDelivery: data.data.scheduled_delivery,
|
||||
scheduledDelivery: data.changedFields.scheduled_delivery?.new,
|
||||
oldScheduledDelivery: data.changedFields.scheduled_delivery?.old
|
||||
},
|
||||
recipients: []
|
||||
@@ -420,8 +400,7 @@ const scheduledDatesChangedBuilder = (data) => {
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
// subject: `Scheduled dates updated for ${data?.jobRoNumber} (${data.bodyShopName})`,
|
||||
body: `Scheduled dates have been updated.`,
|
||||
body,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -433,16 +412,15 @@ const scheduledDatesChangedBuilder = (data) => {
|
||||
|
||||
/**
|
||||
* Builds notification data for supplement imported events.
|
||||
*
|
||||
* @param {Object} data - The data object containing job and supplement details.
|
||||
* @returns {Object} Notification data structured for app, email, and FCM channels.
|
||||
*/
|
||||
const supplementImportedBuilder = (data) => {
|
||||
const body = `A supplement of $${data.data.cieca_ttl?.data?.supp_amt || 0} has been imported.`;
|
||||
const result = {
|
||||
app: {
|
||||
jobId: data.jobId,
|
||||
bodyShopId: data.bodyShopId,
|
||||
key: "notifications.job.supplementImported",
|
||||
body,
|
||||
variables: {
|
||||
suppAmt: data.data.cieca_ttl?.data?.supp_amt
|
||||
},
|
||||
@@ -452,7 +430,7 @@ const supplementImportedBuilder = (data) => {
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `A supplement of $${data.data.cieca_ttl?.data?.supp_amt || 0} has been imported.`,
|
||||
body,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -464,18 +442,17 @@ const supplementImportedBuilder = (data) => {
|
||||
|
||||
/**
|
||||
* Builds notification data for tasks updated or created.
|
||||
*
|
||||
* @param {Object} data - The data object containing job details and task event type.
|
||||
* @returns {Object} Notification data structured for app, email, and FCM channels.
|
||||
*/
|
||||
const tasksUpdatedCreatedBuilder = (data) => {
|
||||
const body = `Tasks have been ${data.isNew ? "created" : "updated"}.`;
|
||||
const result = {
|
||||
app: {
|
||||
jobId: data.jobId,
|
||||
bodyShopId: data.bodyShopId,
|
||||
key: data.isNew ? "notifications.job.taskCreated" : "notifications.job.taskUpdated",
|
||||
body,
|
||||
variables: {
|
||||
type: data.isNew ? "created" : "updated",
|
||||
isNew: data.isNew,
|
||||
roNumber: data.jobRoNumber
|
||||
},
|
||||
recipients: []
|
||||
@@ -484,7 +461,7 @@ const tasksUpdatedCreatedBuilder = (data) => {
|
||||
jobId: data.jobId,
|
||||
jobRoNumber: data.jobRoNumber,
|
||||
bodyShopName: data.bodyShopName,
|
||||
body: `Tasks have been ${data.isNew ? "created" : "updated"}.`,
|
||||
body,
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
|
||||
Reference in New Issue
Block a user