Skip to content

Instantly share code, notes, and snippets.

@hieptl
Created November 16, 2021 02:17
Show Gist options
  • Save hieptl/86d508f06f0abaa08b7464c95da4f568 to your computer and use it in GitHub Desktop.
Save hieptl/86d508f06f0abaa08b7464c95da4f568 to your computer and use it in GitHub Desktop.
posts.js - routes - server - get posts by category - Instagram Clone React Node
app.post('/posts/categories', (req, res) => {
const { userId, postCategory } = req.body;
if (!userId || !postCategory) {
res.status(200).jsonp({ message: 'Cannot load your posts, please try again' });
}
const getPostsSql = "SELECT * FROM post WHERE post_created_by = ? AND post_category = ? ORDER BY post_created_date DESC";
dbConn.query(getPostsSql, [userId, postCategory], function (error, posts) {
if (posts) {
res.status(200).jsonp(posts);
} else {
res.status(200).jsonp({ message: 'Cannot get your posts, please try again' });
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment