Merged in feature/IO-3060-Realtime-Notification-System (pull request #2052)

feature/IO-3060-Realtime-Notifications- Checkpoint
This commit is contained in:
Dave Richer
2025-01-14 17:01:20 +00:00
2 changed files with 41 additions and 24 deletions

View File

@@ -706,7 +706,7 @@
method: POST
query_params: {}
template_engine: Kriti
url: '{{$base_url}}/job/events/handleBillsChange'
url: '{{$base_url}}/notifications/events/handleBillsChange'
version: 2
- name: os_bills
definition:
@@ -4477,7 +4477,7 @@
method: POST
query_params: {}
template_engine: Kriti
url: '{{$base_url}}/job/events/handleJobsChange'
url: '{{$base_url}}/notifications/events/handleJobsChange'
version: 2
- name: os_jobs
definition:
@@ -5137,7 +5137,7 @@
method: POST
query_params: {}
template_engine: Kriti
url: '{{$base_url}}/job/events/handlePartsDispatchChange'
url: '{{$base_url}}/notifications/events/handlePartsDispatchChange'
version: 2
- table:
name: parts_dispatch_lines
@@ -6109,7 +6109,7 @@
_eq: true
check: null
event_triggers:
- name: tasks_assigned_changed
- name: notifications_tasks
definition:
enable_manual: false
insert:
@@ -6119,6 +6119,34 @@
- assigned_to
- completed
- description
retry_conf:
interval_sec: 10
num_retries: 0
timeout_sec: 60
webhook_from_env: HASURA_API_URL
headers:
- name: event-secret
value_from_env: EVENT_SECRET
request_transform:
body:
action: transform
template: |-
{
"success": true
}
method: POST
query_params: {}
template_engine: Kriti
url: '{{$base_url}}/notifications/events/handleTasksChange'
version: 2
- name: tasks_assigned_changed
definition:
enable_manual: false
insert:
columns: '*'
update:
columns:
- assigned_to
retry_conf:
interval_sec: 10
num_retries: 3
@@ -6291,7 +6319,7 @@
method: POST
query_params: {}
template_engine: Kriti
url: '{{$base_url}}/job/events/handleTimeTicketsChange'
url: '{{$base_url}}/notifications/events/handleTimeTicketsChange'
version: 2
- table:
name: transitions

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 });
};
/**