-
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
b8118a8
commit dbb6a93
Showing
6 changed files
with
18 additions
and
20 deletions.
There are no files selected for viewing
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
18 changes: 8 additions & 10 deletions
18
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,21 +1,19 @@ | ||
const { | ||
cohort: { getSpecificCohort }, | ||
} = require('../../../../database/queries'); | ||
const getCohortQuery = require('../../../../database/queries'); | ||
|
||
exports.getSpecificCohort = async (req, res, next) => { | ||
exports.getSpecificCohort = async (req, res) => { | ||
try { | ||
const { cohortid } = req.params; | ||
const { rows } = await getSpecificCohort(cohortid); | ||
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", | ||
}); | ||
throw new Error(); | ||
} | ||
} catch (err) { | ||
next(err); | ||
res.status(404).json({ | ||
statusCode: 404, | ||
message: "Sorry There's no cohort for this id", | ||
}); | ||
} | ||
}; |
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,4 +1,4 @@ | ||
const connection = require('../../config/connection'); | ||
|
||
exports.getSpecificCohort = (id) => | ||
exports.getCohortQuery = (id) => | ||
connection.query('select * from cohort where id = $1', [id]); |
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,3 +1,3 @@ | ||
const { getSpecificCohort } = require('./getSpecificCohort'); | ||
const { getCohortQuery } = require('./getSpecificCohort'); | ||
|
||
module.exports = { getSpecificCohort }; | ||
module.exports = getCohortQuery; |
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,3 +1,3 @@ | ||
const cohort = require('./cohort'); | ||
const getCohortQuery = require('./cohort'); | ||
|
||
module.exports = { cohort }; | ||
module.exports = getCohortQuery; |
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