Merge pull request #14 from yashrajverma/yashrajverma

Updated!
This commit is contained in:
yashraj verma 2021-05-20 12:14:59 +05:30 committed by GitHub
commit b1d0da39a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 10 deletions

View File

@ -4,10 +4,7 @@ const User = require("../models/User");
module.exports.getAllBlogs = async (req, res, next) => {
try {
let blog = await Blog.find().populate(
"author",
"-passwordResetToken -password"
);
let blog = await Blog.find();
if (blog) {
res.json({ blogs: blog });
} else {
@ -22,7 +19,7 @@ module.exports.getAllBlogs = async (req, res, next) => {
};
module.exports.addBlog = async (req, res, next) => {
const { _id, title, body, image } = req.body; //_id is of user from frontend who is adding the blog.
const { _id, title, body, image, author } = req.body; //_id is of user from frontend who is adding the blog.
try {
let user = await User.findById({ _id });
if (!title) {
@ -39,7 +36,7 @@ module.exports.addBlog = async (req, res, next) => {
body,
image,
date: new Date(),
author: user,
author,
});
await blog.save();
res.json({ message: "Blog Saved Successfully!" });
@ -88,12 +85,12 @@ module.exports.editBlog = async (req, res, next) => {
res.status(422).json({ message: "Please, Add the Image of the Blog." });
return;
}
let blog = Blog.findById(_id);
let blog = await Blog.findById({ _id });
if (blog) {
blog.title = title;
blog.body = body;
blog.image = image;
await blog.save();
blog = await blog.save();
res.json({ message: "Blog Updated!" });
} else {
res.status(422).json({ error: "Blog Doesn't Found" });

View File

@ -5,7 +5,7 @@ const blogSchema = new mongoose.Schema({
type: String,
require: true,
},
author: { ref: "User", type: mongoose.Schema.Types.ObjectId },
author: { required: true, type: String },
date: {
type: Date,
},

View File

@ -21,7 +21,7 @@ router.post("/set-coupon", (req, res) => {
});
}
});
router.get("/getAllCoupons", isAuth, isAdmin, couponController.getAllCoupons);
router.get("/getAllCoupons", couponController.getAllCoupons);
router.post("/addCoupon", isAuth, isAdmin, couponController.addCoupon);