-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbb6a93
commit 66c4241
Showing
2 changed files
with
19 additions
and
16 deletions.
There are no files selected for viewing
27 changes: 17 additions & 10 deletions
27
server/controllers/routes/user/cohort/getSpecificCohort.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
const getCohortQuery = require('../../../../database/queries'); | ||
|
||
exports.getSpecificCohort = async (req, res) => { | ||
exports.getSpecificCohort = async (req, res, next) => { | ||
try { | ||
const { cohortid } = req.params; | ||
const { rows } = await getCohortQuery(cohortid); | ||
const data = { ...rows[0] }; | ||
if (data.id) { | ||
res.json({ statusCode: 200, data }); | ||
if (cohortid > 0) { | ||
const { rows } = await getCohortQuery(cohortid); | ||
const data = { ...rows[0] }; | ||
if (data.id) { | ||
res.json({ statusCode: 200, data }); | ||
} else { | ||
res.status(404).json({ | ||
statusCode: 404, | ||
message: "Sorry There's no cohort for this id", | ||
}); | ||
} | ||
} else { | ||
throw new Error(); | ||
res.status(404).json({ | ||
statusCode: 404, | ||
message: 'You enterd wrong cohort ID', | ||
}); | ||
} | ||
} catch (err) { | ||
res.status(404).json({ | ||
statusCode: 404, | ||
message: "Sorry There's no cohort for this id", | ||
}); | ||
next(err); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters