feature/IO-3096-GlobalNotifications - Cleanup and Package bumps
This commit is contained in:
@@ -1,14 +1,29 @@
|
||||
const { getJobAssignmentType } = require("./stringHelpers");
|
||||
|
||||
/**
|
||||
* Populates the recipients for app, email, and FCM notifications based on scenario watchers.
|
||||
*
|
||||
* @param {Object} data - The data object containing scenarioWatchers and bodyShopId.
|
||||
* @param {Object} result - The result object to populate with recipients for app, email, and FCM notifications.
|
||||
*/
|
||||
const populateWatchers = (data, result) => {
|
||||
data.scenarioWatchers.forEach((recipients) => {
|
||||
const { user, app, fcm, email } = 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 });
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 result = {
|
||||
app: {
|
||||
@@ -33,6 +48,12 @@ const alternateTransportChangedBuilder = (data) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 result = {
|
||||
app: {
|
||||
@@ -56,6 +77,12 @@ const billPostedHandler = (data) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 result = {
|
||||
app: {
|
||||
@@ -80,7 +107,14 @@ const criticalPartsStatusChangedBuilder = (data) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 result = {
|
||||
app: {
|
||||
@@ -105,6 +139,12 @@ const intakeDeliveryChecklistCompletedBuilder = (data) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 result = {
|
||||
app: {
|
||||
@@ -128,6 +168,12 @@ const jobAssignedToMeBuilder = (data) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 result = {
|
||||
app: {
|
||||
@@ -149,7 +195,12 @@ const jobsAddedToProductionBuilder = (data) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
// Verified
|
||||
/**
|
||||
* 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 result = {
|
||||
app: {
|
||||
@@ -164,7 +215,7 @@ const jobStatusChangeBuilder = (data) => {
|
||||
},
|
||||
email: {
|
||||
subject: `The status of ${data?.jobRoNumber} (${data.bodyShopName}) has changed from ${data.changedFields.status.old} to ${data.data.status}`,
|
||||
body: `...`,
|
||||
body: `...`, // Placeholder indicating email body may need further customization
|
||||
recipients: []
|
||||
},
|
||||
fcm: { recipients: [] }
|
||||
@@ -174,6 +225,12 @@ const jobStatusChangeBuilder = (data) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 result = {
|
||||
app: {
|
||||
@@ -195,7 +252,12 @@ const newMediaAddedReassignedBuilder = (data) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
// Verified
|
||||
/**
|
||||
* 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 result = {
|
||||
app: {
|
||||
@@ -219,6 +281,12 @@ const newNoteAddedBuilder = (data) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 result = {
|
||||
app: {
|
||||
@@ -240,6 +308,12 @@ const newTimeTicketPostedBuilder = (data) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 result = {
|
||||
app: {
|
||||
@@ -264,6 +338,12 @@ const partMarkedBackOrderedBuilder = (data) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 result = {
|
||||
app: {
|
||||
@@ -287,6 +367,12 @@ const paymentCollectedCompletedBuilder = (data) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 result = {
|
||||
app: {
|
||||
@@ -315,6 +401,12 @@ const scheduledDatesChangedBuilder = (data) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 result = {
|
||||
app: {
|
||||
@@ -338,6 +430,12 @@ const supplementImportedBuilder = (data) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 result = {
|
||||
app: {
|
||||
|
||||
Reference in New Issue
Block a user