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, comments: comments1,
}, },
}, },
function (err, docs) { { new: true }
)
.populate("comments.user", "_id name")
.exec((err, result) => {
if (err) { if (err) {
res.status(503).json({ res.status(503).json({
message: "internal server error cant post the comment", message: "Some Error Occured!" + err,
err,
}); });
} else { } else {
res.status(201).json({ res.status(201).json({
message: "Comment posted!", message: "Comment posted!" + result,
}); });
} }
} });
);
} }
} catch (err) { } catch (err) {
if (err) { if (err) {

View File

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