Skip to content
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 alumin for cohort #61

Merged
merged 9 commits into from
Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions server/controllers/routes/user/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
const router = require('express').Router();

const { getCohortsData, getSpecificCohort } = require('./cohort');
const { getAlumniCohort } = require('./student');
const { getProjectData } = require('./project');

router.get('/cohorts/:cohortId', getSpecificCohort);
router.get('/cohorts', getCohortsData);
router.get('/cohorts/:cohortid', getSpecificCohort);
router.get('/alumni/:cohortId', getAlumniCohort);

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

router.get('/projects/:projectId', getProjectData);

module.exports = router;
27 changes: 27 additions & 0 deletions server/controllers/routes/user/student/getAlumniCohort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { getSpecificAlumnit } = require('../../../../database/queries');

const getAlumniCohort = async (req, res, next) => {
try {
const { cohortId } = req.params;
if (cohortId > 0) {
const { rows } = await getSpecificAlumnit(cohortId);
const data = { ...rows[0] };
ranasobeid95 marked this conversation as resolved.
Show resolved Hide resolved
if (data.id) {
res.json({ statusCode: 200, data });
} else {
res.status(404).json({
statusCode: 404,
message: "Sorry There's no Alumni for this Cohort id",
});
}
} else {
res
.status(404)
.json({ statusCode: 404, message: 'You enterd wrong cohort ID' });
}
} catch (err) {
next(err);
}
};

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

module.exports = {
getAlumniCohort,
};
7 changes: 6 additions & 1 deletion server/database/queries/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const { deleteStudentQuery, putStudent } = require('./student');
const {
deleteStudentQuery,
putStudent,
getSpecificAlumnit,
} = require('./student');
const {
putSpecificCohort,
getCohorts,
Expand Down Expand Up @@ -27,4 +31,5 @@ module.exports = {
putStudent,
getProjectById,
deleteProject,
getSpecificAlumnit,
};
6 changes: 6 additions & 0 deletions server/database/queries/student/getSpecificAlumnit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const connection = require('../../config/connection');

const getSpecificAlumnit = (id) =>
connection.query('select * from cohort where id = $1', [id]);
ranasobeid95 marked this conversation as resolved.
Show resolved Hide resolved

module.exports = getSpecificAlumnit;
2 changes: 2 additions & 0 deletions server/database/queries/student/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const deleteStudentQuery = require('./deleteStudentQuery');
const getSpecificAlumnit = require('./getSpecificAlumnit');
const putStudent = require('./putStudent');

module.exports = {
deleteStudentQuery,
getSpecificAlumnit,
putStudent,
};
28 changes: 28 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@ describe('Delete specific student by ID', () => {
});
});

describe('alumni for cohort', () => {
test('Route /alumni/1 status 200, json header, data.name =G8 ', (done) => {
return request(app)
.get('/api/v1/alumni/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();
});
});
});

describe('Admin, Put project', () => {
const validData = {
name: 'Rehab',
Expand Down Expand Up @@ -320,3 +335,16 @@ describe('Admin, Put project', () => {
});
});
});

test('Route /alumni/10 status 404, json header, data.message = "Sorry There\'s no Alumni for this Cohort id" ', (done) => {
return request(app)
.get('/api/v1/alumni/10')
.expect(404)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) return done(err);
const { message } = res.body;
expect(message).toBe("Sorry There's no Alumni for this Cohort id");
done();
});
});