Skip to content

Commit

Permalink
feat: add new post properties to queries
Browse files Browse the repository at this point in the history
  • Loading branch information
hookor authored and cuconveniencestore committed Aug 26, 2024
1 parent 2189153 commit 18aa26a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion middlewares/validatePostForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const validatePostForm = async form => {
const { brand, menu, size, shot, caffeine, photo } = await form[1];
const nums = checkInt(shot, caffeine);
const validStrings = trimmer([brand, menu, size, photo]);
const length = Object.keys(form[1]).length === 8;
const length = Object.keys(form[1]).length > 8;
return nums && validStrings && length;
};

Expand Down
18 changes: 15 additions & 3 deletions models/posts-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@ exports.getPostDetail = async postReq => {
};

exports.registerPost = async postReq => {
const { brand, menu, post_title, size, shot, caffeine, photo, postId } =
await postReq[1];
const {
brand,
menu,
post_title,
size,
shot,
caffeine,
photo,
postId,
intensity,
description
} = await postReq[1];
const params = [
postReq[0],
brand,
Expand All @@ -30,7 +40,9 @@ exports.registerPost = async postReq => {
shot,
caffeine,
photo,
postId
postId,
intensity,
description
];
const result = await connectAndQuery(PostQueries.registerPost, params);
const data = result[0];
Expand Down
6 changes: 4 additions & 2 deletions models/posts-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const query = require('./query-fns');

const queries = {
getPostDetail: `SELECT
a.brand, a.menu, a.post_title,size, a.shot,caffeine, a.photo, a.created_at, b.profileUrl, b.nickname, b.sum, b.public_id AS userId
a.brand, a.menu, a.post_title,size, a.shot,caffeine, a.photo, a.created_at, a.description, a.intensity, b.profileUrl, b.nickname, b.sum, b.public_id AS userId
FROM post a
LEFT JOIN user b
ON a.user_id = b.public_id
Expand All @@ -16,7 +16,9 @@ const queries = {
'shot',
'caffeine',
'photo',
'public_id'
'public_id',
'description',
'intensity'
]),
deletePost: query.buildDelete('post', ['public_id']),
writeComment: query.buildInsert('comment', ['user_id', 'post_id', 'content']),
Expand Down

0 comments on commit 18aa26a

Please sign in to comment.