-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
relates #14
- Loading branch information
Showing
9 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const { clientError, serverError } = require('./error'); | ||
|
||
module.exports = { | ||
clientError, | ||
serverError, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const deleteCohort = require('./deleteCohort'); | ||
|
||
module.exports = { | ||
deleteCohort, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |