-
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.
I created query function which search for cohort based on id which came from params, and I created the necessary middleware for this function to work in addition to handling the required /cohort/:cohortid route Relates #19
- Loading branch information
1 parent
9ddec52
commit c63ae6a
Showing
7 changed files
with
30 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
const router = require('express').Router(); | ||
const { | ||
cohort: { getSpecificCohort }, | ||
} = require('./routes/user'); | ||
|
||
router.get('/', (req, res) => { | ||
res.send('<h1>CA WIKI</h1>'); | ||
}); | ||
|
||
router.get('/cohort/:cohortid', getSpecificCohort); | ||
|
||
module.exports = router; |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const { | ||
cohort: { getSpecificCohort }, | ||
} = require('../../../../database/queries'); | ||
|
||
exports.getSpecificCohort = (req, res) => { | ||
getSpecificCohort(req.params.cohortid) | ||
.then(({ rows }) => res.json(rows)) | ||
.catch((err) => console.error(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { getSpecificCohort } = require('./getSpecificCohort'); | ||
|
||
module.exports = { getSpecificCohort }; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const cohort = require('./cohort'); | ||
|
||
module.exports = { cohort }; |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const connection = require('../../config/connection'); | ||
|
||
exports.getSpecificCohort = (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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { getSpecificCohort } = require('./getSpecificCohort'); | ||
|
||
module.exports = { getSpecificCohort }; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const cohort = require('./cohort'); | ||
|
||
module.exports = { cohort }; |