From 432f93fc4f06d8604391b4a4665114a431df90cc Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 27 Nov 2025 18:25:59 +0530 Subject: [PATCH] Update establishment API action_done_by filed change added --- app/controllers/establishment.controller.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/controllers/establishment.controller.js b/app/controllers/establishment.controller.js index 6e6226f..ff01ce1 100644 --- a/app/controllers/establishment.controller.js +++ b/app/controllers/establishment.controller.js @@ -600,6 +600,12 @@ exports.updateEstablishment = async (req, res) => { return res.status(400).json({ status:"failed", message:"establishment_code already exists" }); } } + const resolveActionDoneBy = (item) => { + if (item?.action_done_by) return item.action_done_by; + + if (req.user.role === "Admin") return "admin_users"; + return "establishment_users"; + }; estData.updated_by = estData.updated_by || req.user.id; estData.updated_at = estData.updated_at || new Date(); // update establishment @@ -688,7 +694,8 @@ exports.updateEstablishment = async (req, res) => { { is_active: 0, updated_by: removedData?.updated_by , - action_done_by: removedData?.action_done_by || null, + // action_done_by: removedData?.action_done_by || null, + action_done_by: req.user.role === "Admin" ? "admin_users" : "establishment_users", updated_at: new Date() }, { @@ -709,7 +716,8 @@ exports.updateEstablishment = async (req, res) => { product_id: item.product_id, is_active: 1, created_by: item.created_by || null, - action_done_by: item.action_done_by, + // action_done_by: item.action_done_by, + action_done_by: resolveActionDoneBy(item), created_at: new Date() }); } @@ -722,7 +730,8 @@ exports.updateEstablishment = async (req, res) => { { is_active: 1, updated_by: item.updated_by || null, - action_done_by: item.action_done_by, + // action_done_by: item.action_done_by, + action_done_by: resolveActionDoneBy(item), updated_at: new Date() }, {