Skip to content

Instantly share code, notes, and snippets.

@hieptl
Created November 16, 2021 02:26
Show Gist options
  • Save hieptl/7478c8eb53b2a23785b81018b5552b32 to your computer and use it in GitHub Desktop.
Save hieptl/7478c8eb53b2a23785b81018b5552b32 to your computer and use it in GitHub Desktop.
reactions.js - routs - server - check existing reaction - Instagram Clone React Node
app.post('/reactions/get', (req, res) => {
const { post_id, user_id } = req.body;
if (!post_id || !user_id) {
res.status(200).jsonp({ message: 'Not found' });
}
const getReactionSql = "SELECT * FROM post_reaction WHERE post_id = ? AND user_id = ?";
dbConn.query(getReactionSql, [post_id, user_id], function (error, response) {
if (response && response.length) {
res.status(200).jsonp({ ...response[0] });
} 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