const viewAllReviews = (req, res, next) => {
|
ParentTable.findOneById(req.params.id)
|
.then((resp) => {
|
const r = resp;
|
if (resp.user_ratings.length > 0) {
|
for (let i = 0; i < resp.user_ratings.length; i += 1) {
|
ChildTable.findOneById(resp.user_ratings[i].userId)
|
.then((users) => {
|
r.user_ratings[i] = {
|
ratings: resp.user_ratings[i].ratings,
|
comments: resp.user_ratings[i].comments,
|
comment_added: resp.user_ratings[i].comment_added,
|
comment_updated: resp.user_ratings[i].comment_updated,
|
commentId: resp.user_ratings[i].commentId,
|
userId: resp.user_ratings[i].userId,
|
|
// data from user collection
|
username: users.username,
|
displayname: users.displayname,
|
profilepicture: users.profilepicture
|
};
|
|
if (i === resp.user_ratings.length - 1) {
|
res.result(resp.user_ratings, 200, next);
|
}
|
});
|
}
|
} else {
|
res.result(r.user_ratings, 200, next);
|
}
|
})
|
.catch(e => next(e));
|
};
|