feature/IO-2924-Refactor-Production-Board-For-Sockets - Checkpoint

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-09-12 17:29:48 -04:00
parent a08125df54
commit 2f3056b49b
5 changed files with 169 additions and 32 deletions

View File

@@ -2,6 +2,12 @@ const { isObject } = require("lodash");
const jobUpdated = async (req, res) => {
const { io, logger } = req;
logger.log("job-update", "INFO", req.user?.email, null, {
message: `Job updated event received from Hasura`,
body: req?.body
});
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`,
@@ -13,9 +19,14 @@ const jobUpdated = async (req, res) => {
message: `Malformed Job Update request sent from Hasura`
});
}
const bodyshopID = req.body.event.data.new.shopid;
return res.json({ message: "Job updated" });
const updatedJob = req.body.event.data.new;
const bodyshopID = updatedJob.shopid;
// Emit the job-updated event only to the room corresponding to the bodyshop
io.to(bodyshopID).emit("job-updated", updatedJob);
return res.json({ message: "Job updated and event emitted" });
};
module.exports = jobUpdated;