From bdbaca011992729e0cbe312c4b887bb81f630c3b Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 27 Nov 2025 12:19:43 +0530 Subject: [PATCH] Esatablishment inactive api updated for inactive action --- app/controllers/establishment.controller.js | 24 ++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app/controllers/establishment.controller.js b/app/controllers/establishment.controller.js index 16ddcbe..d169bed 100644 --- a/app/controllers/establishment.controller.js +++ b/app/controllers/establishment.controller.js @@ -605,6 +605,26 @@ exports.updateEstablishment = async (req, res) => { // update establishment await establishment.update(estData); + if (req.body.is_active === false) { + await EstablishmentUser.update( + { + is_active : false, + updated_by: req.user.id, + updated_at: new Date() + }, + { where: { establishment_id: id } } + ); + + await EstablishmentProduct.update( + { + is_active : false, + updated_by: req.user.id, + updated_at: new Date() + }, + { where: { establishment_id: id } } + ); + } + // update user if needed if (establishment_user) { const user = await EstablishmentUser.findOne({where:{establishment_id:id}}); @@ -613,6 +633,7 @@ exports.updateEstablishment = async (req, res) => { name: establishment_user.name, email: establishment_user.email }; + if (establishment_user.password) { updateUser.password = await bcrypt.hash(establishment_user.password,10); } @@ -680,7 +701,6 @@ exports.updateEstablishment = async (req, res) => { ); } - // ADD new active products const newItems = incoming.filter(p => !oldIds.includes(p.product_id)); @@ -716,8 +736,6 @@ exports.updateEstablishment = async (req, res) => { } } - - return res.json({ status:"success", message:"Updated successfully" , data:"" }); } catch(err) {