From ac292945b13d8e27c16c6a2b4a0f6e618170e772 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 20 Jan 2026 12:19:31 +0530 Subject: [PATCH] Duplicate email admin user restricted --- app/controllers/establishment.controller.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/controllers/establishment.controller.js b/app/controllers/establishment.controller.js index e7c7067..db3f6bb 100644 --- a/app/controllers/establishment.controller.js +++ b/app/controllers/establishment.controller.js @@ -176,6 +176,8 @@ exports.createEstablishment = async (req, res) => { const existingUser = await EstablishmentUser.findOne({ where: { email: establishment_user.email } }); + + const checkEmailInAdminUser = await User.findOne({ where: { email, is_active: true } }); if (existingUser) { return res.status(400).send({ @@ -184,6 +186,14 @@ exports.createEstablishment = async (req, res) => { }); } + if (checkEmailInAdminUser) { + logger.info(`Email already exists in Admin Users: ${email}`); + return res.status(409).send({ + status: "failed", + message: "This email address is already registered in the admin users." + }); + } + // Create establishment record const establishment = await Establishment.create({ establishment_code: sanitizeStringValue(establishment_code),