Skip to content

Commit

Permalink
populate comment to user
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuyisenge2 committed Mar 31, 2024
1 parent 055fffd commit 5d1420b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/controllers/comment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ return res.status(201).json({
});
}
let Arraycom:string[]=[];
const comments = await Comment.find({ blogId: id });
const comments = await Comment.find({ blogId: id })
.populate({path:'User',select:['firstname','lastname']});

await Promise.all(comments.map(async (item) => {
Arraycom.push(item.comment as string);
Expand All @@ -97,11 +98,11 @@ return res.status(201).json({
message: 'No comments found'
});
}

console.log(Arraycom)
return res.status(200).json({
status:'ok',
message: 'Comments retrieved successfully',
Comments: Arraycom
Comments: comments
});
} catch (error) {
console.error('Error:', error);
Expand Down

0 comments on commit 5d1420b

Please sign in to comment.