router.route('/ajax/fetch-user').get((req, res) => { const db = dbUtil.getDB(); db.collection('users').findOne({publicKey: req.query.pk}, function(err, user){ res.json({ user: user}); }); });
router.route('/ajax/get-comment-upvote-status').get((req, res) => { const db = dbUtil.getDB(); const publicKey = req.query.pk; if (!req.query.commentIds) { return res.json({ status: {} }); } const commentIds = req.query.commentIds.split(','); if (commentIds.length === 0) { return res.json({ status: {} }); } db.collection('users').findOne({publicKey: publicKey}, function(err, user){ const status = {}; async.each(commentIds, (commentId, cb) => { db.collection('usercommentvotes').find({ userID: ObjectId(user._id), commentID: ObjectId(commentId) }).count(function(err, count){ if (count > 0) { status[commentId] = true; } cb(); }); }, () => { res.json({ status: status }); }); }); });
router.route('/ajax/get-upvote-status').get((req, res) => { const db = dbUtil.getDB(); const publicKey = req.query.pk; if (!req.query.postIds) { return res.json({ status: {} }); } const postIds = req.query.postIds.split(','); if (postIds.length === 0) { return res.json({ status: {} }); } db.collection('users').findOne({publicKey: publicKey}, function(err, user){ const status = {}; async.each(postIds, (postId, cb) => { db.collection('userpostvotes').find({ userID: ObjectId(user._id), postID: ObjectId(postId) }).count(function(err, count){ if (count > 0) { status[postId] = true; } cb(); }); }, () => { res.json({ status: status }); }); }); });