-
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.
Showing
13 changed files
with
380 additions
and
219 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const { postCohort } = require('../../../../database/queries'); | ||
const cohortSchema = require('../../../../validation/cohortSchema '); | ||
|
||
const addCohort = async (req, res, next) => { | ||
try { | ||
await cohortSchema.validate(req.body, { abortEarly: false }); | ||
const { rows } = await postCohort(req.body); | ||
const { name } = rows[0]; | ||
res.status(201).json({ | ||
StatusCode: 201, | ||
data: { | ||
cohort: rows[0], | ||
message: `Cohort with Key (name)=(${name}) added successfully`, | ||
}, | ||
}); | ||
} catch (err) { | ||
if (err.errors) { | ||
res.status(400).json({ statusCode: 400, data: { message: err.errors } }); | ||
} else if (err.detail) { | ||
res.status(409).json({ | ||
statusCode: 409, | ||
data: { | ||
message: err.detail, | ||
}, | ||
}); | ||
} else { | ||
next(err); | ||
} | ||
} | ||
}; | ||
|
||
module.exports = addCohort; |
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 editCohort = require('./editCohort'); | ||
const addCohort = require('./addCohort'); | ||
const deleteCohort = require('./deleteCohort'); | ||
const editCohort = require('./editCohort'); | ||
|
||
module.exports = { | ||
addCohort, | ||
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
Empty file.
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,3 @@ | ||
const { getProjectById } = require('./getProjectById'); | ||
|
||
module.exports = { getProjectById }; |
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,11 @@ | ||
const connection = require('../../config/connection'); | ||
|
||
const postCohort = (reqData) => { | ||
const { name, description, imgUrl, githubLink } = reqData; | ||
return connection.query( | ||
'INSERT INTO cohort (name, description, img_url, github_link) VALUES ($1, $2, $3, $4) RETURNING *;', | ||
[name, description, imgUrl, githubLink], | ||
); | ||
}; | ||
|
||
module.exports = postCohort; |
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 @@ | ||
const yup = require('yup'); | ||
|
||
const cohortSchema = yup.object({ | ||
name: yup.string().required(), | ||
description: yup.string().required(), | ||
imgUrl: yup.string().url().required(), | ||
githubLink: yup.string().url().required(), | ||
}); | ||
|
||
module.exports = cohortSchema; |
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,9 @@ | ||
const cohortSchema = require('./cohortSchema '); | ||
const { editCohortSchema } = require('./editCohort'); | ||
|
||
const projectSchema = require('./projectSchema'); | ||
|
||
module.exports = { | ||
cohortSchema, | ||
projectSchema, | ||
editCohortSchema, | ||
}; |
Oops, something went wrong.