Skip to content

Commit

Permalink
modify addProjectQuerey argument
Browse files Browse the repository at this point in the history
relates #24
  • Loading branch information
MohammedAlghazali committed Mar 31, 2020
1 parent 076f4cc commit 11e4888
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
19 changes: 1 addition & 18 deletions server/controllers/routes/admin/project/addProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
20 changes: 11 additions & 9 deletions server/database/queries/project/addProject.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 11e4888

Please sign in to comment.