Created
November 16, 2021 02:22
-
-
Save hieptl/3a15b1047303064176bf3bea510a256c to your computer and use it in GitHub Desktop.
followers.js - routes - server - create follower - 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('/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