Skip to content

Commit

Permalink
fix conflict ???
Browse files Browse the repository at this point in the history
realtes #26
  • Loading branch information
MohammedAlghazali committed Apr 3, 2020
2 parents 3d97041 + ce3e61a commit 5c78128
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dev": "NODE_ENV=development nodemon server/index.js",
"project-setup": "npm install && cd client && npm install",
"heroku-postbuild": "cd client && npm install && npm run build",
"test": "NODE_ENV=test jest --runInBand --coverage",
"test": "NODE_ENV=test jest --no-cache --runInBand --coverage",
"kill": "fuser -k 5000/tcp",
"lint": "eslint server/",
"lint-fix": "eslint server/ --fix",
Expand Down
5 changes: 3 additions & 2 deletions server/controllers/routes/user/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const router = require('express').Router();

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

router.get('/alumni', getAlumni);
router.get('/cohorts/:cohortId', getSpecificCohort);
router.get('/projects', getProjectsData);
router.get('/cohorts', getCohortsData);
router.get('/cohorts/:cohortId', getSpecificCohort);
router.get('/projects/:projectId', getProjectData);

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

const getProjectsData = async (req, res, next) => {
try {
const { type } = req.query;
if (
type.toLowerCase() === 'internal' ||
type.toLowerCase() === 'remotely'
) {
const { rows } = await getProjects(type);
if (rows.length > 0) {
res.json({
statusCode: 200,
data: rows,
});
} else {
res.json({
statusCode: 200,
message: `There is no ${type} projects`,
});
}
} else {
res.status(404).json({
statusCode: 404,
message: 'Please enter valid type',
});
}
} catch (err) {
next(err);
}
};

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

module.exports = {
getProjectsData,
getProjectData,
};
2 changes: 2 additions & 0 deletions server/database/queries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
getProjectById,
deleteProject,
getCohortProjectsQuery,
getProjects,
} = require('./project');

module.exports = {
Expand All @@ -29,4 +30,5 @@ module.exports = {
putStudent,
getProjectById,
deleteProject,
getProjects,
};
9 changes: 9 additions & 0 deletions server/database/queries/project/getProjectsByType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const connection = require('../../config/connection');

const getProjects = (ProjectType) =>
connection.query(
'SELECT * FROM project WHERE project_type ilike $1 ORDER BY name',
[ProjectType],
);

module.exports = getProjects;
2 changes: 2 additions & 0 deletions server/database/queries/project/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const getProjects = require('./getProjectsByType');
const addProjectQuery = require('./addProject');
const getCohortProjectsQuery = require('./getCohortProjects');
const editProjectQuery = require('./editProject');
const getProjectById = require('./getProjectById');
const deleteProject = require('./deleteProject');

module.exports = {
getProjects,
addProjectQuery,
getCohortProjectsQuery,
editProjectQuery,
Expand Down
28 changes: 28 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,34 @@ describe('Delete specific student by ID', () => {
});
});

describe('Get project by type', () => {
test('Route /projects?type=internal status 200, json header, rows[0].name = Applicants System ', (done) => {
return request(app)
.get('/api/v1/projects?type=internal')
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) return done(err);
const { name } = res.body.data[0];
expect(name).toBe('Applicants System');
done();
});
});

test('Route /projects?type=g58g status 404, json header ', (done) => {
return request(app)
.get('/api/v1/projects?type=gg')
.expect(404)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) return done(err);
const { message } = res.body;
expect(message).toBe('Please enter valid type');
done();
});
});
});

describe('Admin, Put project', () => {
const validData = {
name: 'Rehab',
Expand Down

0 comments on commit 5c78128

Please sign in to comment.