IO-2924-Refactor-Production-board-to-use-Socket-Provider: rough in backend logic
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
32
server/job/job-updated.js
Normal file
32
server/job/job-updated.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const { isObject } = require("lodash");
|
||||
|
||||
const jobUpdated = async (req, res) => {
|
||||
const { ioRedis, logger } = 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", "INFO", 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(bodyshopID).emit("job-updated", updatedJob);
|
||||
|
||||
return res.json({ message: "Job updated and event emitted" });
|
||||
};
|
||||
|
||||
module.exports = jobUpdated;
|
||||
@@ -14,3 +14,4 @@ exports.costing = require("./job-costing").JobCosting;
|
||||
exports.costingmulti = require("./job-costing").JobCostingMulti;
|
||||
exports.statustransition = require("./job-status-transition").statustransition;
|
||||
exports.lifecycle = require("./job-lifecycle");
|
||||
exports.jobUpdated = require("./job-updated");
|
||||
|
||||
Reference in New Issue
Block a user