Last active
October 13, 2021 06:51
-
-
Save hieptl/db0687017c027bd1384fdac9b1e97332 to your computer and use it in GitHub Desktop.
users.js - API - Recommend Users
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
const transformRecommendedUsers = (users) => { | |
if (users && users.length !== 0) { | |
return users.map(user => { | |
return { | |
id: user.id, | |
user_age: user.user_age, | |
user_avatar: user.user_avatar, | |
user_cometchat_uid: user.user_cometchat_uid, | |
user_email: user.user_email, | |
user_full_name: user.user_full_name, | |
user_gender: user.user_gender | |
} | |
}); | |
} | |
return users; | |
} | |
app.post('/users/recommend', (req, res) => { | |
const { gender, ccUid } = req.body; | |
if (gender && ccUid) { | |
const sql = "SELECT * FROM user_account WHERE user_gender = ? AND (user_cometchat_uid NOT IN (SELECT match_request_to FROM match_request WHERE match_request_from = ?) AND user_cometchat_uid NOT IN (SELECT match_request_from FROM match_request WHERE match_request_to = ? AND match_request_status = ?))"; | |
dbConn.query(sql, [gender, ccUid, ccUid, constants.matchRequestStatus.accepted], function (err, result) { | |
if (err) { | |
res.status(200).jsonp({ message: 'Cannot get your recommended users, please try again' }); | |
} else { | |
const recommendedUsers = transformRecommendedUsers(result); | |
res.status(200).jsonp(recommendedUsers); | |
} | |
}); | |
} else { | |
res.status(200).jsonp({ message: "Please provide cometchat uid and user's gender" }); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment