feature/IO-3060-Realtime-Notifications- Checkpoint

This commit is contained in:
Dave Richer
2025-01-13 07:27:10 -08:00
parent 3bc6504ae6
commit 8a0916a47f
25 changed files with 188 additions and 69 deletions

View File

@@ -142,27 +142,38 @@ const sendMail = (type, to, subject, html, taskIds, successCallback, requestInst
* @returns {Promise<*>}
*/
const taskAssignedEmail = async (req, res) => {
// We have no event Data, bail
// 1. Check if we have new task data in the event body.
if (!req?.body?.event?.data?.new) {
return res.status(400).json({ message: "No data in the event body" });
}
const { new: newTask } = req.body.event.data;
const { new: newTask, old: oldTask } = req.body.event.data;
// This is not a new task, but a reassignment.
const dirty = req.body.event.data?.old && req.body.event.data?.old?.assigned_to;
// TODO: THIS IS HERE BECAUSE THE HANDLER NOW DOES 3 FIELDS, WILL NEED TO BE BUILT ON FOR NOTIFICATIONS
if (oldTask && oldTask.assigned_to === newTask.assigned_to) {
return res.status(200).json({ success: true, message: "assigned_to not changed" });
}
//Query to get the employee assigned currently.
// 3. If we made it here, assigned_to changed (or oldTask is missing),
// so we continue with the rest of the logic.
// Query to get the task with bodyshop data, assigned employee data, etc.
const { tasks_by_pk } = await client.request(queries.QUERY_TASK_BY_ID, {
id: newTask.id
});
// Format date/time with the correct timezone
const dateLine = moment().tz(tasks_by_pk.bodyshop.timezone).format("M/DD/YYYY @ hh:mm a");
// This determines if it was re-assigned (old task exists and had an assigned_to).
const dirty = oldTask && oldTask.assigned_to;
sendMail(
"assigned",
tasks_by_pk.assigned_to_employee.user_email,
`A ${formatPriority(newTask.priority)} priority task has been ${dirty ? "reassigned to" : "created for"} you - ${newTask.title}`,
`A ${formatPriority(newTask.priority)} priority task has been ${
dirty ? "reassigned" : "created"
} for you - ${newTask.title}`,
generateEmailTemplate(
generateTemplateArgs(
newTask.title,
@@ -181,8 +192,8 @@ const taskAssignedEmail = async (req, res) => {
tasks_by_pk.bodyshop.convenient_company
);
// We return success regardless because we don't want to block the event trigger.
res.status(200).json({ success: true });
// Return success so we don't block the event trigger.
return res.status(200).json({ success: true });
};
/**