Skip to content

Commit

Permalink
Get cohort based on id
Browse files Browse the repository at this point in the history
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
Mu7ammadAbed committed Mar 28, 2020
1 parent 9ddec52 commit c63ae6a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/controllers/index.js
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;
9 changes: 9 additions & 0 deletions server/controllers/routes/user/cohort/getSpecificCohort.js
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));
};
3 changes: 3 additions & 0 deletions server/controllers/routes/user/cohort/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { getSpecificCohort } = require('./getSpecificCohort');

module.exports = { getSpecificCohort };
3 changes: 3 additions & 0 deletions server/controllers/routes/user/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const cohort = require('./cohort');

module.exports = { cohort };
4 changes: 4 additions & 0 deletions server/database/queries/cohort/getSpecificCohort.js
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}`]);
3 changes: 3 additions & 0 deletions server/database/queries/cohort/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { getSpecificCohort } = require('./getSpecificCohort');

module.exports = { getSpecificCohort };
3 changes: 3 additions & 0 deletions server/database/queries/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const cohort = require('./cohort');

module.exports = { cohort };

0 comments on commit c63ae6a

Please sign in to comment.