Created
November 16, 2021 02:16
-
-
Save hieptl/a3dce44f34eb19342fae59306059e603 to your computer and use it in GitHub Desktop.
posts.js - routes - server - get post by id - 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.get('/posts/:id', (req, res) => { | |
const id = req.params.id; | |
const getPostSql = "SELECT post.id, post_content, post_category, post_created_date, post_created_by, post_number_of_reactions, user_account.user_avatar, user_account.user_full_name, user_account.user_number_of_followers FROM post INNER JOIN user_account ON post.post_created_by = user_account.id WHERE post.id = ?"; | |
if (!id) { | |
res.status(200).jsonp({ message: 'Cannot load the post detail, please try again' }); | |
} | |
dbConn.query(getPostSql, [id], function (error, response) { | |
if (response && response.length) { | |
res.status(200).jsonp(response); | |
} else { | |
res.status(200).jsonp({ message: 'Not found' }); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment