Merged in release/2025-01-17 (pull request #2053)

Release/2025 01 17 into test-AIO - IO-1927, IO-3022, IO-3060, IO-3078, IO-3080, IO-3082
This commit is contained in:
Dave Richer
2025-01-14 17:02:26 +00:00
13 changed files with 92 additions and 59 deletions

View File

@@ -142,38 +142,27 @@ const sendMail = (type, to, subject, html, taskIds, successCallback, requestInst
* @returns {Promise<*>}
*/
const taskAssignedEmail = async (req, res) => {
// 1. Check if we have new task data in the event body.
// We have no event Data, bail
if (!req?.body?.event?.data?.new) {
return res.status(400).json({ message: "No data in the event body" });
}
const { new: newTask, old: oldTask } = req.body.event.data;
const { new: newTask } = req.body.event.data;
// 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" });
}
// This is not a new task, but a reassignment.
const dirty = req.body.event.data?.old && req.body.event.data?.old?.assigned_to;
// 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.
//Query to get the employee assigned currently.
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" : "created"
} for you - ${newTask.title}`,
`A ${formatPriority(newTask.priority)} priority task has been ${dirty ? "reassigned to" : "created for"} you - ${newTask.title}`,
generateEmailTemplate(
generateTemplateArgs(
newTask.title,
@@ -192,8 +181,8 @@ const taskAssignedEmail = async (req, res) => {
tasks_by_pk.bodyshop.convenient_company
);
// Return success so we don't block the event trigger.
return res.status(200).json({ success: true });
// We return success regardless because we don't want to block the event trigger.
res.status(200).json({ success: true });
};
/**