From 3a0fd47b8048d5eec180aa99c2ba1cd5cf83b21d Mon Sep 17 00:00:00 2001 From: MohammedAlghazali Date: Mon, 30 Mar 2020 20:22:31 +0300 Subject: [PATCH] check if cohort id not found relates #24 --- .../routes/admin/cohort/deleteCohort.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/server/controllers/routes/admin/cohort/deleteCohort.js b/server/controllers/routes/admin/cohort/deleteCohort.js index 93da68a7..36c77aaf 100644 --- a/server/controllers/routes/admin/cohort/deleteCohort.js +++ b/server/controllers/routes/admin/cohort/deleteCohort.js @@ -2,11 +2,17 @@ const { deleteCohort } = require('../../../../database/queries'); const cohortDelete = async (req, res, next) => { try { - await deleteCohort(req.params.cohortId); - res.json({ - StatusCode: 200, - data: { message: 'Cohort deleted successfully' }, - }); + const test = await deleteCohort(req.params.cohortId); + if (test.rowCount !== 0) { + res.json({ + StatusCode: 200, + data: { message: 'Cohort deleted successfully' }, + }); + } else { + const err = new Error(); + err.msg = 'chohrt id not found'; + next(err); + } } catch (err) { next(err); }