Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
relates #14
  • Loading branch information
AlaaSaadeddin committed Apr 1, 2020
2 parents 93f41cd + 33f0796 commit cd3d005
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@ const router = require('express').Router();
const userRouter = require('./routes/user');

router.use(userRouter);
const admin = require('./routes/admin');

const { clientError, serverError } = require('./middlewares/errorHandle');

router.use(clientError);
router.use(serverError);

router.use(admin);

module.exports = router;
10 changes: 10 additions & 0 deletions server/controllers/middlewares/errorHandle/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable no-unused-vars */
exports.clientError = (req, res) => {
res.status(404).json({ StatusCode: '404', title: 'page not found 404' });
};

exports.serverError = (err, req, res, next) => {
res
.status(500)
.json({ StatusCode: '500', title: 'internal server error 500', err });
};
6 changes: 6 additions & 0 deletions server/controllers/middlewares/errorHandle/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { clientError, serverError } = require('./error');

module.exports = {
clientError,
serverError,
};
23 changes: 23 additions & 0 deletions server/controllers/routes/admin/cohort/deleteCohort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { deleteCohortQuery } = require('../../../../database/queries');

const deleteCohort = async (req, res, next) => {
try {
const { cohortId } = req.params;
const check = await deleteCohortQuery(cohortId);
if (check.rowCount !== 0) {
res.json({
StatusCode: 200,
data: { message: 'Cohort deleted successfully' },
});
} else {
res.status(404).json({
StatusCode: 404,
data: { message: 'Cohort does not exist' },
});
}
} catch (err) {
next(err);
}
};

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

module.exports = {
deleteCohort,
};
21 changes: 21 additions & 0 deletions server/controllers/routes/admin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const router = require('express').Router();
const { deleteCohort } = require('./cohort');

router
.route('/cohorts/:cohortId')
.all((req, res, next) => {
// ToDo: make middleware to check authentication
next();
})
.get((req, res, next) => {
next(new Error('not implemented'));
})
.put((req, res, next) => {
next(new Error('not implemented'));
})
.post((req, res, next) => {
next(new Error('not implemented'));
})
.delete(deleteCohort);

module.exports = router;
6 changes: 6 additions & 0 deletions server/database/queries/cohort/deleteCohort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const connection = require('../../config/connection');

const deleteCohortQuery = (cohortId) =>
connection.query('DELETE FROM cohort WHERE id = $1', [cohortId]);

module.exports = deleteCohortQuery;
8 changes: 8 additions & 0 deletions server/database/queries/cohort/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<<<<<<< HEAD
const { getCohorts } = require('./getCohorts');

module.exports = { getCohorts };
=======
const deleteCohortQuery = require('./deleteCohort');

module.exports = {
deleteCohortQuery,
};
>>>>>>> master
8 changes: 8 additions & 0 deletions server/database/queries/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<<<<<<< HEAD
const { getCohorts } = require('./cohort');

module.exports = { getCohorts };
=======
const { deleteCohortQuery } = require('./cohort');

module.exports = {
deleteCohortQuery,
};
>>>>>>> master

0 comments on commit cd3d005

Please sign in to comment.