Skip to content

Instantly share code, notes, and snippets.

@hieptl
Created November 16, 2021 02:16
Show Gist options
  • Save hieptl/a3dce44f34eb19342fae59306059e603 to your computer and use it in GitHub Desktop.
Save hieptl/a3dce44f34eb19342fae59306059e603 to your computer and use it in GitHub Desktop.
posts.js - routes - server - get post by id - Instagram Clone React Node
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