Skip to content

Instantly share code, notes, and snippets.

@hieptl
Created November 16, 2021 02:28
Show Gist options
  • Save hieptl/63c67ed190503ae0538262463cd90739 to your computer and use it in GitHub Desktop.
Save hieptl/63c67ed190503ae0538262463cd90739 to your computer and use it in GitHub Desktop.
reactions.js - routes - server - create reaction - Instagram Clone React Node
app.post('/reactions/create', (req, res) => {
const { postId, userId } = req.body;
if (!postId || !userId) {
res.status(200).jsonp({ message: 'Cannot create the post reaction, please try again' });
}
const reactions = [[postId, userId]];
const insertReactionSql = "INSERT INTO post_reaction (post_id, user_id) VALUES ?";
dbConn.query(insertReactionSql, [reactions], function (error, insertedReaction) {
if (insertedReaction) {
res.status(200).jsonp({ insertId: insertedReaction.insertId, post_id: postId, user_id: userId });
} else {
res.status(200).jsonp({ message: 'Cannot create the post reaction, please try again' });
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment