feature/IO-3291-Tasks-Notifications: Checkpoint
This commit is contained in:
@@ -152,9 +152,56 @@ const handlePaymentsChange = async (req, res) =>
|
||||
* @param {Object} res - Express response object.
|
||||
* @returns {Promise<Object>} JSON response with a success message.
|
||||
*/
|
||||
const handleTasksChange = async (req, res) =>
|
||||
const handleTasksChange = async (req, res) => {
|
||||
console.log("Handling tasks change notification...!!!!!!!!!!!!");
|
||||
// Handle Notification Event
|
||||
processNotificationEvent(req, res, "req.body.event.new.jobid", "Tasks Notifications Event Handled.");
|
||||
|
||||
const {
|
||||
logger,
|
||||
ioRedis,
|
||||
ioHelpers: { getBodyshopRoom }
|
||||
} = req;
|
||||
const event = req.body.event;
|
||||
const op = event.op;
|
||||
let taskData;
|
||||
let type;
|
||||
let bodyshopId;
|
||||
|
||||
if (op === "INSERT") {
|
||||
taskData = event.data.new;
|
||||
if (taskData.deleted) {
|
||||
logger.log("tasks-event-insert-deleted", "warn", "notifications", null, { id: taskData.id });
|
||||
} else {
|
||||
type = "task-created";
|
||||
bodyshopId = taskData.bodyshopid;
|
||||
}
|
||||
} else if (op === "UPDATE") {
|
||||
const newData = event.data.new;
|
||||
const oldData = event.data.old;
|
||||
taskData = newData;
|
||||
bodyshopId = newData.bodyshopid;
|
||||
|
||||
if (newData.deleted && !oldData.deleted) {
|
||||
type = "task-deleted";
|
||||
taskData = { id: newData.id };
|
||||
} else if (!newData.deleted && oldData.deleted) {
|
||||
type = "task-created";
|
||||
} else if (!newData.deleted) {
|
||||
type = "task-updated";
|
||||
}
|
||||
} else {
|
||||
logger.log("tasks-event-unknown-op", "warn", "notifications", null, { op });
|
||||
}
|
||||
|
||||
if (bodyshopId && ioRedis && type) {
|
||||
const room = getBodyshopRoom(bodyshopId);
|
||||
ioRedis.to(room).emit("bodyshop-message", { type, payload: taskData });
|
||||
logger.log("tasks-event-emitted", "info", "notifications", null, { type, bodyshopId });
|
||||
} else if (type) {
|
||||
logger.log("tasks-event-missing-data", "error", "notifications", null, { bodyshopId, hasIo: !!ioRedis, type });
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Handle time tickets change notifications.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user