-
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 #49 from GSG-G8/23-put-cohortid
23 put cohortid
- Loading branch information
Showing
14 changed files
with
169 additions
and
12 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
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,31 @@ | ||
const { putSpecificCohort } = require('../../../../database/queries'); | ||
const { editCohortSchema } = require('../../../../validation/index'); | ||
|
||
const editCohort = async (req, res, next) => { | ||
try { | ||
const { cohortId } = req.params; | ||
const data = await editCohortSchema.validate( | ||
{ ...req.body, cohortId }, | ||
{ | ||
abortEarly: false, | ||
}, | ||
); | ||
const result = await putSpecificCohort(data); | ||
if (result.rowCount === 1) { | ||
res.json({ statusCode: 200, message: 'Changed Succefully' }); | ||
} else { | ||
res.status(404).json({ | ||
statusCode: 404, | ||
message: "Sorry There's no cohort for this id to change", | ||
}); | ||
} | ||
} catch (err) { | ||
if (err.errors) { | ||
res.status(400).json({ statusCode: 400, message: err.errors }); | ||
} else { | ||
next(err); | ||
} | ||
} | ||
}; | ||
|
||
module.exports = editCohort; |
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,7 @@ | ||
const editCohort = require('./editCohort'); | ||
const deleteCohort = require('./deleteCohort'); | ||
|
||
module.exports = { deleteCohort }; | ||
module.exports = { | ||
deleteCohort, | ||
editCohort, | ||
}; |
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
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,4 +1,7 @@ | ||
const { getCohortsData } = require('./getCohortsData'); | ||
const getCohortsData = require('./getCohortsData'); | ||
const getSpecificCohort = require('./getSpecificCohort'); | ||
|
||
module.exports = { getCohortsData, getSpecificCohort }; | ||
module.exports = { | ||
getCohortsData, | ||
getSpecificCohort, | ||
}; |
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,7 +1,9 @@ | ||
const router = require('express').Router(); | ||
|
||
const { getCohortsData } = require('./cohort'); | ||
const { getSpecificCohort } = require('./cohort'); | ||
|
||
router.get('/cohorts', getCohortsData); | ||
router.get('/cohorts/:cohortid', getSpecificCohort); | ||
|
||
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
const putSpecificCohort = require('./putSpecificCohort'); | ||
const getCohorts = require('./getCohorts'); | ||
|
||
const getCohortQuery = require('./getSpecificCohort'); | ||
|
||
const deleteCohortQuery = require('./deleteCohort'); | ||
|
||
module.exports = { | ||
getCohorts, | ||
deleteCohortQuery, | ||
putSpecificCohort, | ||
getCohortQuery, | ||
}; |
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,11 @@ | ||
const connection = require('../../config/connection'); | ||
|
||
const putSpecificCohort = (req) => { | ||
const { name, description, imgUrl, githubLink, cohortId } = req; | ||
return connection.query( | ||
'UPDATE cohort SET name = $1, description = $2, img_url = $3, github_link = $4 WHERE id = $5 ', | ||
[name, description, imgUrl, githubLink, cohortId], | ||
); | ||
}; | ||
|
||
module.exports = putSpecificCohort; |
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,9 @@ | ||
const yup = require('yup'); | ||
|
||
exports.editCohortSchema = yup.object({ | ||
cohortId: yup.number().required(), | ||
name: yup.string().required(), | ||
description: yup.string().required(), | ||
imgUrl: yup.string().url().required(), | ||
githubLink: yup.string().url().required(), | ||
}); |
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,5 +1,8 @@ | ||
const { editCohortSchema } = require('./editCohort'); | ||
|
||
const projectSchema = require('./projectSchema'); | ||
|
||
module.exports = { | ||
projectSchema, | ||
editCohortSchema, | ||
}; |
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