Skip to content

Commit

Permalink
handle /almuni route, query, function
Browse files Browse the repository at this point in the history
relates #26
  • Loading branch information
MohammedAlghazali committed Apr 1, 2020
1 parent dc8ec49 commit 55c12af
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 1 deletion.
2 changes: 2 additions & 0 deletions server/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const router = require('express').Router();

const admin = require('./routes/admin');
const { getSpecificCohort } = require('./routes/user');
const { getAlumni } = require('./routes/user');

router.get('/alumni', getAlumni);
router.get('/cohorts/:cohortid', getSpecificCohort);
router.use(admin);

Expand Down
3 changes: 2 additions & 1 deletion server/controllers/routes/user/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { getSpecificCohort } = require('./cohort');
const { getAlumni } = require('./student');

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

const getAlumni = async (req, res, next) => {
try {
const { rows } = await getAlumniQuery();
res.json({ statusCode: 200, data: rows });
} catch (err) {
next(err);
}
};

module.exports = getAlumni;
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 getAlumni = require('./getAlumni');

module.exports = {
getAlumni,
};
2 changes: 2 additions & 0 deletions server/database/queries/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const { getCohortQuery } = require('./cohort');
const { deleteCohortQuery } = require('./cohort');
const { addProjectQuery } = require('./project');
const { getAlumniQuery } = require('./student');

module.exports = {
deleteCohortQuery,
getCohortQuery,
addProjectQuery,
getAlumniQuery,
};
5 changes: 5 additions & 0 deletions server/database/queries/student/getAlumni.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const connection = require('../../config/connection');

const getAlumniQuery = () => connection.query('SELECT * FROM student');

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

module.exports = {
getAlumniQuery,
};
16 changes: 16 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,19 @@ describe('Admin, (/cohorts/:cohortId)', () => {
});
});
});

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

0 comments on commit 55c12af

Please sign in to comment.