Skip to content

Instantly share code, notes, and snippets.

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