Skip to content

Commit

Permalink
Edit route name
Browse files Browse the repository at this point in the history
  • Loading branch information
Mu7ammadAbed committed Mar 31, 2020
1 parent b8118a8 commit dbb6a93
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion server/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ const {
cohort: { getSpecificCohort },
} = require('./routes/user');

router.get('/cohort/:cohortid', getSpecificCohort);
router.get('/cohorts/:cohortid', getSpecificCohort);

module.exports = router;
18 changes: 8 additions & 10 deletions server/controllers/routes/user/cohort/getSpecificCohort.js
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",
});
}
};
2 changes: 1 addition & 1 deletion server/database/queries/cohort/getSpecificCohort.js
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]);
4 changes: 2 additions & 2 deletions server/database/queries/cohort/index.js
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;
4 changes: 2 additions & 2 deletions server/database/queries/index.js
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;
8 changes: 4 additions & 4 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ afterAll(() => {
});

describe('Cohort', () => {
test('Route /cohort/1 status 200, json header, data.name =G8 ', (done) => {
test('Route /cohorts/1 status 200, json header, data.name =G8 ', (done) => {
return request(app)
.get('/api/v1/cohort/1')
.get('/api/v1/cohorts/1')
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
Expand All @@ -26,9 +26,9 @@ describe('Cohort', () => {
});
});

test('Route /cohort/10 status 404, json header, data.message = "Sorry There\'s no cohort for this id" ', (done) => {
test('Route /cohorts/10 status 404, json header, data.message = "Sorry There\'s no cohort for this id" ', (done) => {
return request(app)
.get('/api/v1/cohort/10')
.get('/api/v1/cohorts/10')
.expect(404)
.expect('Content-Type', /json/)
.end((err, res) => {
Expand Down

0 comments on commit dbb6a93

Please sign in to comment.