-
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.
Merge pull request #43 from GSG-G8/29-DELETE-cohort
handle Delete cohort route Close #29
- Loading branch information
Showing
9 changed files
with
98 additions
and
3 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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
const router = require('express').Router(); | ||
const admin = require('./routes/admin'); | ||
|
||
const { clientError, serverError } = require('./middlewares/errorHandle'); | ||
|
||
router.use(clientError); | ||
router.use(serverError); | ||
|
||
router.use(admin); | ||
|
||
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,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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const deleteCohortQuery = require('./deleteCohort'); | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const { deleteCohortQuery } = require('./cohort'); | ||
|
||
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,28 @@ | ||
test('Initial test', () => { | ||
expect(1).toBe(1); | ||
const request = require('supertest'); | ||
const connection = require('../server/database/config/connection'); | ||
const dbBuild = require('../server/database/config/build'); | ||
|
||
const app = require('../server/app'); | ||
|
||
beforeAll(() => dbBuild()); | ||
|
||
afterAll(() => connection.end()); | ||
|
||
describe('Admin, (/cohorts/:cohortId)', () => { | ||
test('Route /cohorts/1 status 200, data.message = Cohort deleted successfully ', (done) => { | ||
return request(app) | ||
.delete('/api/v1/cohorts/1') | ||
.expect(200) | ||
.expect('Content-Type', /json/) | ||
.end(async (err, res) => { | ||
const { message } = res.body.data; | ||
if (err) return done(err); | ||
const { rows } = await connection.query( | ||
'SELECT * from cohort WHERE id = 1', | ||
); | ||
expect(rows).toHaveLength(0); | ||
expect(message).toBe('Cohort deleted successfully'); | ||
done(); | ||
}); | ||
}); | ||
}); |