From 11e48882e5458b10610b47d8979a679c6fb07e92 Mon Sep 17 00:00:00 2001 From: MohammedAlghazali Date: Tue, 31 Mar 2020 15:28:22 +0300 Subject: [PATCH] modify addProjectQuerey argument relates #24 --- .../routes/admin/project/addProject.js | 19 +----------------- server/database/queries/project/addProject.js | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/server/controllers/routes/admin/project/addProject.js b/server/controllers/routes/admin/project/addProject.js index b89fcc8f..733e9c25 100644 --- a/server/controllers/routes/admin/project/addProject.js +++ b/server/controllers/routes/admin/project/addProject.js @@ -3,25 +3,8 @@ const { addProjectSchema } = require('../../../../validation'); const addProject = async (req, res, next) => { try { - const { - name, - description, - imgUrl, - githubLink, - websiteLink, - projectType, - cohortId, - } = req.body; await addProjectSchema.validate(req.body); - await addProjectQuery( - name, - description, - imgUrl, - githubLink, - websiteLink, - projectType, - cohortId, - ); + await addProjectQuery(req.body); res.json({ StatusCode: 200, data: { message: 'Cohort Added successfully' }, diff --git a/server/database/queries/project/addProject.js b/server/database/queries/project/addProject.js index 1dfe38ba..1bb0ba5a 100644 --- a/server/database/queries/project/addProject.js +++ b/server/database/queries/project/addProject.js @@ -1,17 +1,19 @@ const connection = require('../../config/connection'); -const addProjectQuery = ( - name, - description, - imgUrl, - githubLink, - websiteLink, - projectType, - cohortId, -) => +const addProjectQuery = (data) => { + const { + name, + description, + imgUrl, + githubLink, + websiteLink, + projectType, + cohortId, + } = data; 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 = addProjectQuery;