User Posted

This commit is contained in:
yashrajverma 2021-06-04 18:50:03 +05:30
parent 8b77a7e19f
commit 54046c404c
2 changed files with 9 additions and 7 deletions

View File

@ -136,19 +136,20 @@ module.exports.commentBlog = async (req, res, next) => {
comments: comments1,
},
},
function (err, docs) {
{ new: true }
)
.populate("comments.user", "_id name")
.exec((err, result) => {
if (err) {
res.status(503).json({
message: "internal server error cant post the comment",
err,
message: "Some Error Occured!" + err,
});
} else {
res.status(201).json({
message: "Comment posted!",
message: "Comment posted!" + result,
});
}
}
);
});
}
} catch (err) {
if (err) {

View File

@ -23,7 +23,7 @@ const blogSchema = new mongoose.Schema({
},
comments: [
{
user: { type: mongoose.Schema.Types.ObjectId, ref: "Users" },
user: { ref: "User", type: mongoose.Types.ObjectId },
review: {
type: String,
},
@ -32,5 +32,6 @@ const blogSchema = new mongoose.Schema({
},
},
],
user: { ref: "User", type: mongoose.Types.ObjectId },
});
module.exports = mongoose.model("Blog", blogSchema);