IO-3166-Global-Notifications-Part-2: checkpoint
This commit is contained in:
@@ -50,13 +50,69 @@ const handleBillsChange = async (req, res) =>
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle documents change notifications.
|
* Handle documents change notifications.
|
||||||
|
* Processes both old and new job IDs if the document was moved between jobs.
|
||||||
*
|
*
|
||||||
* @param {Object} req - Express request object.
|
* @param {Object} req - Express request object.
|
||||||
* @param {Object} res - Express response object.
|
* @param {Object} res - Express response object.
|
||||||
* @returns {Promise<Object>} JSON response with a success message.
|
* @returns {Promise<Object>} JSON response with a success message.
|
||||||
*/
|
*/
|
||||||
const handleDocumentsChange = async (req, res) =>
|
const handleDocumentsChange = async (req, res) => {
|
||||||
processNotificationEvent(req, res, "req.body.event.new.jobid", "Documents Change Notifications Event Handled.");
|
const { logger } = req;
|
||||||
|
const newJobId = req.body?.event?.data?.new?.jobid;
|
||||||
|
const oldJobId = req.body?.event?.data?.old?.jobid;
|
||||||
|
|
||||||
|
// If jobid changed (document moved between jobs), we need to notify both jobs
|
||||||
|
if (oldJobId && newJobId && oldJobId !== newJobId) {
|
||||||
|
// Process notification for new job ID
|
||||||
|
scenarioParser(req, "req.body.event.new.jobid").catch((error) => {
|
||||||
|
logger.log("notifications-error", "error", "notifications", null, {
|
||||||
|
message: error?.message,
|
||||||
|
stack: error?.stack
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create a modified request for old job ID
|
||||||
|
const oldJobReq = {
|
||||||
|
body: {
|
||||||
|
...req.body,
|
||||||
|
event: {
|
||||||
|
...req.body.event,
|
||||||
|
data: {
|
||||||
|
new: {
|
||||||
|
...req.body.event.data.old,
|
||||||
|
// Add a flag to indicate this document was moved away
|
||||||
|
_documentMoved: true,
|
||||||
|
_movedToJob: newJobId
|
||||||
|
},
|
||||||
|
old: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
logger,
|
||||||
|
sessionUtils: req.sessionUtils
|
||||||
|
};
|
||||||
|
|
||||||
|
// Process notification for old job ID using the modified request
|
||||||
|
scenarioParser(oldJobReq, "req.body.event.new.jobid").catch((error) => {
|
||||||
|
logger.log("notifications-error", "error", "notifications", null, {
|
||||||
|
message: error?.message,
|
||||||
|
stack: error?.stack
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(200).json({ message: "Documents Change Notifications Event Handled for both jobs." });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise just process the new job ID
|
||||||
|
scenarioParser(req, "req.body.event.new.jobid").catch((error) => {
|
||||||
|
logger.log("notifications-error", "error", "notifications", null, {
|
||||||
|
message: error?.message,
|
||||||
|
stack: error?.stack
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(200).json({ message: "Documents Change Notifications Event Handled." });
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle job lines change notifications.
|
* Handle job lines change notifications.
|
||||||
|
|||||||
@@ -261,10 +261,12 @@ const newMediaAddedReassignedBuilder = (data) => {
|
|||||||
|
|
||||||
// Determine the action
|
// Determine the action
|
||||||
let action;
|
let action;
|
||||||
if (data.isNew) {
|
if (data?.data?._documentMoved) {
|
||||||
|
action = "moved to another Job"; // Special case for document moved from this job
|
||||||
|
} else if (data.isNew) {
|
||||||
action = "added"; // New media
|
action = "added"; // New media
|
||||||
} else if (data.changedFields?.jobid && data.changedFields.jobid.old !== data.changedFields.jobid.new) {
|
} else if (data.changedFields?.jobid && data.changedFields.jobid.old !== data.changedFields.jobid.new) {
|
||||||
action = "reassigned to Job";
|
action = "moved to this Job";
|
||||||
} else {
|
} else {
|
||||||
action = "updated";
|
action = "updated";
|
||||||
}
|
}
|
||||||
@@ -281,7 +283,8 @@ const newMediaAddedReassignedBuilder = (data) => {
|
|||||||
body,
|
body,
|
||||||
variables: {
|
variables: {
|
||||||
mediaType,
|
mediaType,
|
||||||
action
|
action,
|
||||||
|
movedToJob: data?.data?._movedToJob
|
||||||
},
|
},
|
||||||
recipients: []
|
recipients: []
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user