From c613d5b35cd639169d987985138e4ea30a3b38f2 Mon Sep 17 00:00:00 2001 From: MohammedAlghazali Date: Mon, 30 Mar 2020 20:37:37 +0300 Subject: [PATCH] check if cohort id exist or not relates #29 --- .../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 c65377fb..8d904bb2 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/cohort/deleteCohort') const cohortDelete = async (req, res, next) => { try { - await deleteCohort(req.params.cohortId); - res.json({ - StatusCode: 200, - data: { message: 'Cohort deleted successfully' }, - }); + const check = await deleteCohort(req.params.cohortId); + if (check.rowCount !== 0) { + res.json({ + StatusCode: 200, + data: { message: 'Cohort deleted successfully' }, + }); + } else { + const err = new Error(); + err.message = 'cohort id does not exist'; + next(err); + } } catch (err) { next(err); }