From f8b4264ccf5b31fa959a511cee99a81ec34f908f Mon Sep 17 00:00:00 2001 From: MohammedAlghazali Date: Mon, 30 Mar 2020 15:37:58 +0300 Subject: [PATCH] make query to add project data in project table relates #24 --- server/controllers/routes/admin/index.js | 3 +++ .../routes/admin/project/addProject.js | 0 .../controllers/routes/admin/project/index.js | 7 +++++++ .../routes/admin/project/validateAddProject.js | 0 server/database/queries/project/addProject.js | 17 +++++++++++++++++ 5 files changed, 27 insertions(+) create mode 100644 server/controllers/routes/admin/project/addProject.js create mode 100644 server/controllers/routes/admin/project/validateAddProject.js create mode 100644 server/database/queries/project/addProject.js diff --git a/server/controllers/routes/admin/index.js b/server/controllers/routes/admin/index.js index 097affbd..b1f7613a 100644 --- a/server/controllers/routes/admin/index.js +++ b/server/controllers/routes/admin/index.js @@ -1,5 +1,6 @@ const router = require('express').Router(); const { cohortDelete } = require('./cohort'); +const { cohortAdd, validateAddProject } = require('./project'); router .route('/cohorts/:cohortId') @@ -19,4 +20,6 @@ router }) .delete(cohortDelete); +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 new file mode 100644 index 00000000..e69de29b diff --git a/server/controllers/routes/admin/project/index.js b/server/controllers/routes/admin/project/index.js index e69de29b..0999a013 100644 --- a/server/controllers/routes/admin/project/index.js +++ b/server/controllers/routes/admin/project/index.js @@ -0,0 +1,7 @@ +const { cohortAdd } = require('./addProject'); +const validateAddProject = require('./validateAddProject'); + +module.exports = { + cohortAdd, + validateAddProject, +}; diff --git a/server/controllers/routes/admin/project/validateAddProject.js b/server/controllers/routes/admin/project/validateAddProject.js new file mode 100644 index 00000000..e69de29b diff --git a/server/database/queries/project/addProject.js b/server/database/queries/project/addProject.js new file mode 100644 index 00000000..4ce0491b --- /dev/null +++ b/server/database/queries/project/addProject.js @@ -0,0 +1,17 @@ +const connection = require('../../config/connection'); + +const addCohort = ( + name, + description, + imgUrl, + githubLink, + websiteLink, + projectType, + cohortId, +) => + connection.query( + 'INSERT INTO project (name, description, img_url, github_link, website_link, project_type, cohort_id) VALUES ($1, $2, $3, $4, $5, $6, $7)', + [name, description, imgUrl, githubLink, websiteLink, projectType, cohortId], + ); + +module.exports = addCohort;