diff --git a/server/controllers/routes/admin/index.js b/server/controllers/routes/admin/index.js index 53e20ee0..b1f7613a 100644 --- a/server/controllers/routes/admin/index.js +++ b/server/controllers/routes/admin/index.js @@ -1,6 +1,6 @@ const router = require('express').Router(); const { cohortDelete } = require('./cohort'); -const { validateAddProject } = require('./project'); +const { cohortAdd, validateAddProject } = require('./project'); router .route('/cohorts/:cohortId') @@ -20,6 +20,6 @@ router }) .delete(cohortDelete); -router.post('/projects', validateAddProject); +router.post('/projects', validateAddProject, cohortAdd); module.exports = router; diff --git a/server/controllers/routes/admin/project/addProject.js b/server/controllers/routes/admin/project/addProject.js index e69de29b..73a765d5 100644 --- a/server/controllers/routes/admin/project/addProject.js +++ b/server/controllers/routes/admin/project/addProject.js @@ -0,0 +1,34 @@ +const addProject = require('../../../../database/queries/project/addProject'); + +const cohortAdd = async (req, res, next) => { + try { + const { + name, + description, + imgUrl, + githubLink, + websiteLink, + projectType, + cohortId, + } = req.body; + await addProject( + name, + description, + imgUrl, + githubLink, + websiteLink, + projectType, + cohortId, + ); + res.json({ + StatusCode: 200, + data: { message: 'Cohort Added successfully' }, + }); + } catch (err) { + next(err); + } +}; + +module.exports = { + cohortAdd, +};