Skip to content

Commit

Permalink
check if cohort id exist or not
Browse files Browse the repository at this point in the history
relates #29
  • Loading branch information
MohammedAlghazali committed Mar 30, 2020
1 parent fa8c6f0 commit c613d5b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions server/controllers/routes/admin/cohort/deleteCohort.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit c613d5b

Please sign in to comment.