From fa8c6f0c47c4aeae5df2256a9b688f3a4af40192 Mon Sep 17 00:00:00 2001 From: MohammedAlghazali Date: Mon, 30 Mar 2020 12:31:55 +0300 Subject: [PATCH] convert promise to async/await in deleteCohort.js relates #29 --- .../routes/admin/cohort/deleteCohort.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/server/controllers/routes/admin/cohort/deleteCohort.js b/server/controllers/routes/admin/cohort/deleteCohort.js index bf408c87..c65377fb 100644 --- a/server/controllers/routes/admin/cohort/deleteCohort.js +++ b/server/controllers/routes/admin/cohort/deleteCohort.js @@ -1,14 +1,15 @@ const deleteCohort = require('../../../../database/queries/cohort/deleteCohort'); -const cohortDelete = (req, res, next) => { - deleteCohort(req.params.cohortId) - .then(() => - res.json({ - StatusCode: 200, - data: { message: 'Cohort deleted successfully' }, - }), - ) - .catch(next); +const cohortDelete = async (req, res, next) => { + try { + await deleteCohort(req.params.cohortId); + res.json({ + StatusCode: 200, + data: { message: 'Cohort deleted successfully' }, + }); + } catch (err) { + next(err); + } }; module.exports = {