Created
November 16, 2021 02:28
-
-
Save hieptl/63c67ed190503ae0538262463cd90739 to your computer and use it in GitHub Desktop.
reactions.js - routes - server - create reaction - 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('/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