Created
November 16, 2021 02:17
-
-
Save hieptl/86d508f06f0abaa08b7464c95da4f568 to your computer and use it in GitHub Desktop.
posts.js - routes - server - get posts by category - Instagram Clone React Node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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