Skip to content

Commit

Permalink
check if cohort id not found
Browse files Browse the repository at this point in the history
relates #24
  • Loading branch information
MohammedAlghazali committed Mar 30, 2020
1 parent 82105fb commit 3a0fd47
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');

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);
}
Expand Down

0 comments on commit 3a0fd47

Please sign in to comment.