My server returns an empty object if it gets to the last condition, where code is 204:
exports.get_group_profile = function(req, res) {
Work.findById(req.params.work_id, function(err, work) {
if (err || !work)
return res.send(404);
if (work.admin.id === req.user._id){
console.log('here');
return res.json(200, work.profile);
}
if (work.users.indexOf(req.user._id)> -1)
return res.json(201, work.profile);
if (work.invited.indexOf(req.user._id) > -1)
return res.json(202, work.profile);
for (var i=0;i<work.appliers.length;i++) {
if (work.appliers[i].id == req.user._id)
return res.json(203, work.profile);
}
if (work.visibility!=0){
console.log(work.profile);
return res.json(204, work.profile);
}
return res.send(404);
});
};
Any condition but this one returns work.profile (which is a virtual in mongoDB) properly. The log before the return prints the object I need but I have no trace of it on my client side. Any idea ?