Skip to content

Commit

Permalink
fix comment query
Browse files Browse the repository at this point in the history
  • Loading branch information
millionhz committed Dec 10, 2022
1 parent 101d252 commit 71a21f6
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions server/utilities/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,31 @@ const toggleFollow = (userId, myUserId) =>
});

const getCommentsById = (postId) => {
const sql = `SELECT comment_id, content, comments.created_time, name FROM (SELECT * FROM comments WHERE post_id = ? AND is_deleted = 0) as comments INNER JOIN users ON comments.user_id = users.user_id;`;

const sql = `
SELECT
comment_id,
content,
comments.created_time,
name
FROM
(
SELECT
*
FROM
comments
WHERE
post_id = ?
AND is_deleted = 0
) as comments
INNER JOIN (
SELECT
*
FROM
users
WHERE
users.is_activated = 1
) AS users ON comments.user_id = users.user_id;
`;
return query(sql, [postId]);
};

Expand Down

0 comments on commit 71a21f6

Please sign in to comment.