Files
bodyshop/server/job/job-updated.js
Dave Richer 3f247a9227 release/2024-11-01 - Misc fixes
Signed-off-by: Dave Richer <dave@imexsystems.ca>
2024-10-29 09:54:45 -07:00

33 lines
1021 B
JavaScript

const { isObject } = require("lodash");
const jobUpdated = async (req, res) => {
const { ioRedis, logger, ioHelpers } = req;
if (!req?.body?.event?.data?.new || !isObject(req?.body?.event?.data?.new)) {
logger.log("job-update-error", "ERROR", req.user?.email, null, {
message: `Malformed Job Update request sent from Hasura`,
body: req?.body
});
return res.json({
status: "error",
message: `Malformed Job Update request sent from Hasura`
});
}
logger.log("job-update", "DEBUG", req.user?.email, null, {
message: `Job updated event received from Hasura`,
jobid: req?.body?.event?.data?.new?.id
});
const updatedJob = req.body.event.data.new;
const bodyshopID = updatedJob.shopid;
// Emit the job-updated event only to the room corresponding to the bodyshop
ioRedis.to(ioHelpers.getBodyshopRoom(bodyshopID)).emit("production-job-updated", updatedJob);
return res.json({ message: "Job updated and event emitted" });
};
module.exports = jobUpdated;