From eec559af89697eafc0b37df11d68ac44cd960732 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Fri, 26 Jan 2024 10:59:21 +0300 Subject: [PATCH] fixed error on assign case --- routes/processes/case.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/routes/processes/case.js b/routes/processes/case.js index fc51f31..d2bff77 100644 --- a/routes/processes/case.js +++ b/routes/processes/case.js @@ -65,13 +65,18 @@ router.post("/assign", async (req, res) => { message: `Phone number: ${phone_no} is not active in the system.` }); - let existing_assigned = await caseAssign.count({ + let existing_assigned = await caseAssign.findOne({ where: { client_id: check_client.id } }); - if (existing_assigned === 0) { + if (existing_assigned) { + return res.status(400).json({ + success: false, + message: `Client ${clinic_number} is already assigned to a case manager` + }); + } else { try { await caseAssign.create({ client_id: check_client.id, @@ -94,11 +99,6 @@ router.post("/assign", async (req, res) => { message: `Error occurred while assigning a case. Please try again.` }); } - } else { - return res.status(400).json({ - success: false, - message: `Client ${clinic_number} is already assigned to a case manager` - }); } });