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 all 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
2 changes: 2 additions & 0 deletions server/controllers/routes/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const router = require('express').Router();
const { getAlumni } = require('./student');
const { getProjectData, getProjectsData } = require('./project');
const { getCohortsData, getSpecificCohort } = require('./cohort');
const { getAlumniCohort } = require('./student');

router.get('/cohorts/:cohortId/alumni', getAlumniCohort);
router.get('/alumni', getAlumni);
router.get('/projects', getProjectsData);
router.get('/cohorts', getCohortsData);
Expand Down
20 changes: 20 additions & 0 deletions server/controllers/routes/user/student/getAlumniCohort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { getSpecificAlumni } = require('../../../../database/queries');

const getAlumniCohort = async (req, res, next) => {
try {
const { cohortId } = req.params;
if (cohortId > 0) {
const { rows } = await getSpecificAlumni(cohortId);
res.json({ statusCode: 200, data: rows });
} else {
res.status(404).json({
statusCode: 404,
message: 'cohort does not exists',
});
}
} catch (err) {
next(err);
}
};

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

module.exports = {
getAlumniCohort,
getAlumni,
};
9 changes: 8 additions & 1 deletion server/database/queries/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
const { getAlumniQuery, deleteStudentQuery, putStudent } = require('./student');
const {
getAlumniQuery,
deleteStudentQuery,
putStudent,
getSpecificAlumni,
} = require('./student');

const {
putSpecificCohort,
getCohorts,
Expand Down Expand Up @@ -30,6 +36,7 @@ module.exports = {
putStudent,
getProjectById,
deleteProject,
getSpecificAlumni,
getProjects,
getStatsQuery,
};
6 changes: 6 additions & 0 deletions server/database/queries/student/getSpecificAlumni.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const connection = require('../../config/connection');

const getSpecificAlumni = (id) =>
connection.query('SELECT * FROM student WHERE cohort_id = $1', [id]);

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

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

describe('alumni for cohort', () => {
test('Route /cohorts/10/alumni status 200, json header ', (done) => {
return request(app)
.get('/api/v1/cohorts/10/alumni')
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) return done(err);
const { data } = res.body;
expect(data).toHaveLength(0);
done();
});
});
test('Route /cohorts/g/alumni status 404, json header, data.message = "cohort does not exists" ', (done) => {
return request(app)
.get('/api/v1/cohorts/g/alumni')
.expect(404)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) return done(err);
const { message } = res.body;
expect(message).toBe('cohort does not exists');
done();
});
});
});

describe('Get project by type', () => {
test('Route /projects?type=internal status 200, json header, rows[0].name = Applicants System ', (done) => {
return request(app)
Expand Down Expand Up @@ -384,6 +411,19 @@ describe('Admin, Put project', () => {
});
});

test('Route /cohorts/2/alumni status 200, json header, data.name =Alaa ', (done) => {
return request(app)
.get('/api/v1/cohorts/2/alumni')
.expect(200)
.expect('Content-Type', /json/)
.end(async (err, res) => {
if (err) return done(err);
const { data } = res.body;
expect(data[0].name).toBe('Rana');
done();
});
});

describe('Get stats', () => {
test('Route /stats status 200, json header ', (done) => {
return request(app)
Expand Down