-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GET cohort by id #41
GET cohort by id #41
Changes from 12 commits
c63ae6a
cc66060
11afe2a
6799acb
204b6c7
e4a0de3
2668f05
39d706d
cbcea25
3c5a336
24cc213
b8118a8
dbb6a93
66c4241
f26364b
3425783
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
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; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,21 @@ | ||||||
const { | ||||||
cohort: { getSpecificCohort }, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest making destructure of getSpecificCohort in const { getSpecificCohort } = require('./cohort');
module.exports = { getSpecificCohort }; as you make in and here in this file you can make require to getSpecificCohort as
Suggested change
so we get more benefit from |
||||||
} = require('../../../../database/queries'); | ||||||
|
||||||
exports.getSpecificCohort = async (req, res, next) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Mu7ammadAbed Since you don't use |
||||||
try { | ||||||
const { cohortid } = req.params; | ||||||
const { rows } = await getSpecificCohort(cohortid); | ||||||
const data = { ...rows[0] }; | ||||||
if (data.id) { | ||||||
res.json({ statusCode: 200, data }); | ||||||
} else { | ||||||
res.status(404).json({ | ||||||
ranasobeid95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
statusCode: 404, | ||||||
message: "Sorry There's no cohort for this id", | ||||||
}); | ||||||
} | ||||||
} catch (err) { | ||||||
next(err); | ||||||
} | ||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { getSpecificCohort } = require('./getSpecificCohort'); | ||
|
||
module.exports = { getSpecificCohort }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const cohort = require('./cohort'); | ||
|
||
module.exports = { cohort }; |
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]); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { getSpecificCohort } = require('./getSpecificCohort'); | ||
|
||
module.exports = { getSpecificCohort }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const cohort = require('./cohort'); | ||
|
||
module.exports = { cohort }; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,3 +1,41 @@ | ||||||
test('Initial test', () => { | ||||||
expect(1).toBe(1); | ||||||
const request = require('supertest'); | ||||||
const connection = require('../server/database/config/connection'); | ||||||
const dbBuild = require('../server/database/config/build'); | ||||||
|
||||||
const app = require('../server/app'); | ||||||
|
||||||
beforeAll(() => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need
Suggested change
|
||||||
return dbBuild(); | ||||||
}); | ||||||
|
||||||
afterAll(() => { | ||||||
return connection.end(); | ||||||
}); | ||||||
|
||||||
describe('Cohort', () => { | ||||||
test('Route /cohort/1 status 200, json header, data.name =G8 ', (done) => { | ||||||
return request(app) | ||||||
.get('/api/v1/cohort/1') | ||||||
.expect(200) | ||||||
.expect('Content-Type', /json/) | ||||||
.end((err, res) => { | ||||||
if (err) return done(err); | ||||||
const { data } = res.body; | ||||||
expect(data.name).toBe('G8'); | ||||||
done(); | ||||||
}); | ||||||
}); | ||||||
ranasobeid95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
test('Route /cohort/10 status 404, json header, data.message = "Sorry There\'s no cohort for this id" ', (done) => { | ||||||
return request(app) | ||||||
.get('/api/v1/cohort/10') | ||||||
.expect(404) | ||||||
ranasobeid95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
.expect('Content-Type', /json/) | ||||||
.end((err, res) => { | ||||||
if (err) return done(err); | ||||||
const { message } = res.body; | ||||||
expect(message).toBe("Sorry There's no cohort for this id"); | ||||||
done(); | ||||||
}); | ||||||
}); | ||||||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
based on issue #5 please change the route to be
/cohorts/:cohortId