Fixed!
This commit is contained in:
parent
08f0d3a45d
commit
5567767d97
|
@ -1,103 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.find({ _id });
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.find({ _id });
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: course._id,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.find({ _id });
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: course._id,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.find({ _id });
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: course,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.find({ _id });
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: course._id,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,106 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.find({ _id })
|
|
||||||
.populate("_id ")
|
|
||||||
.select("-password");
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: course._id,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,106 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.find({ _id })
|
|
||||||
.populate("_id ")
|
|
||||||
.select("-password");
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: course,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,106 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.find({ _id })
|
|
||||||
.populate("_id ")
|
|
||||||
.select("-password");
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: course._id,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.find({ _id }).populate("").select("-password");
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: course,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.find({ _id });
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: ,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.find({ _id });
|
|
||||||
console.log(course);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.find(_id);
|
|
||||||
console.log(course);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.find({ _id });
|
|
||||||
console.log(course);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.findById({ _id });
|
|
||||||
console.log(course);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.findById({ _id });
|
|
||||||
console.log("Course ", course);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.findById(_id);
|
|
||||||
console.log("Course ", course);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.find(_id);
|
|
||||||
console.log("Course ", course);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.find({ _id });
|
|
||||||
console.log("Course ", course);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.findOne({ _id });
|
|
||||||
console.log("Course ", course);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.findOne({ _id });
|
|
||||||
console.log("Course ", course);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const Course = require("../models/Course");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let course = await Course.find({ _id });
|
|
||||||
console.log("Course ", course);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (course) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.find({ _id });
|
|
||||||
console.log("User ", user);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,105 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.find({ _id });
|
|
||||||
console.log("User ", user);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: user,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,105 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.find({ _id });
|
|
||||||
console.log("User ", user);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: user.firstName + " " + user.lastName,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,105 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.find({ _id });
|
|
||||||
console.log("User ", user);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user._id == _id) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: user.firstName + " " + user.lastName,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,105 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.find({ _id });
|
|
||||||
console.log("User ", user);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user._id == _id) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: user._id,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,105 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.find({ _id });
|
|
||||||
console.log("User ", user);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user._id == _id) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: user,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,105 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.find({ _id });
|
|
||||||
// console.log("User ", user);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user._id == _id) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: user,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,105 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.find({ _id });
|
|
||||||
// console.log("User ", user);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user._id == _id) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: User.find({ _id }),
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,105 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.find({ _id });
|
|
||||||
// console.log("User ", user);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user._id == _id) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: ,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,106 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.find({ _id });
|
|
||||||
// console.log("User ", user);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user._id == _id) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: user.firstName,
|
|
||||||
});
|
|
||||||
console.log("Brfore save", blog);
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,106 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.find({ _id });
|
|
||||||
// console.log("User ", user);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: user.firstName,
|
|
||||||
});
|
|
||||||
console.log("Brfore save", blog);
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,106 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.find({ _id });
|
|
||||||
// console.log("User ", user);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: user,
|
|
||||||
});
|
|
||||||
console.log("Brfore save", blog);
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,105 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.find({ _id });
|
|
||||||
// console.log("User ", user);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
});
|
|
||||||
console.log("Brfore save", blog);
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,106 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.find({ _id });
|
|
||||||
// console.log("User ", user);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author:user.
|
|
||||||
});
|
|
||||||
console.log("Before save", blog);
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,106 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.find({ _id });
|
|
||||||
// console.log("User ", user);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: user,
|
|
||||||
});
|
|
||||||
console.log("Before save", blog);
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,106 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.find({ _id });
|
|
||||||
console.log("User ", user._id);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: user,
|
|
||||||
});
|
|
||||||
// console.log("Before save", blog);
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,106 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.findById({ _id });
|
|
||||||
console.log("User ", user._id);
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: user,
|
|
||||||
});
|
|
||||||
// console.log("Before save", blog);
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,104 +0,0 @@
|
||||||
const { log } = require("handlebars");
|
|
||||||
const Blog = require("../models/Blog");
|
|
||||||
const User = require("../models/User");
|
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find();
|
|
||||||
if (blog) {
|
|
||||||
res.json({ blogs: blog });
|
|
||||||
} else {
|
|
||||||
console.log("Error in Blog", blog);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
try {
|
|
||||||
let user = await User.findById({ _id });
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user) {
|
|
||||||
let blog = new Blog({
|
|
||||||
title,
|
|
||||||
body,
|
|
||||||
image,
|
|
||||||
date: new Date(),
|
|
||||||
author: user,
|
|
||||||
});
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
|
||||||
} else {
|
|
||||||
res.status.json({ error: "User Doesn't Exists" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.deleteBlog = async (req, res, next) => {
|
|
||||||
const { _id } = req.body;
|
|
||||||
try {
|
|
||||||
let blog = await Blog.find({ _id });
|
|
||||||
if (blog) {
|
|
||||||
await Blog.findByIdAndDelete(_id);
|
|
||||||
res.json({ message: "Blog Deleted!" });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Blog Not Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.editBlog = async (req, res, next) => {
|
|
||||||
const { _id, body, title, image } = req.body;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!title) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Title of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!body) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Body of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!image) {
|
|
||||||
res.status(422).json({ message: "Please, Add the Image of the Blog." });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let blog = Blog.findById(_id);
|
|
||||||
if (blog) {
|
|
||||||
blog.title = title;
|
|
||||||
blog.body = body;
|
|
||||||
blog.image = image;
|
|
||||||
await blog.save();
|
|
||||||
res.json({ message: "Blog Updated!" });
|
|
||||||
} else {
|
|
||||||
res.status(422).json({ error: "Blog Doesn't Found" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
(err) => {
|
|
||||||
res.status(422).json({ error: err });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,27 +0,0 @@
|
||||||
const mongoose = require("mongoose");
|
|
||||||
const blogSchema = new mongoose.Schema({
|
|
||||||
title: {
|
|
||||||
type: String,
|
|
||||||
require: true,
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
type: String,
|
|
||||||
ref: "Course",
|
|
||||||
},
|
|
||||||
date: {
|
|
||||||
type: Date,
|
|
||||||
},
|
|
||||||
image: {
|
|
||||||
type: String,
|
|
||||||
default: "",
|
|
||||||
},
|
|
||||||
body: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
isBookMarked: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
module.exports = mongoose.model("Blog", blogSchema);
|
|
|
@ -1,28 +0,0 @@
|
||||||
const mongoose = require("mongoose");
|
|
||||||
const { ObjectId } = mongoose.Schema.Types;
|
|
||||||
const blogSchema = new mongoose.Schema({
|
|
||||||
title: {
|
|
||||||
type: String,
|
|
||||||
require: true,
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
type: ObjectId,
|
|
||||||
ref: "Course",
|
|
||||||
},
|
|
||||||
date: {
|
|
||||||
type: Date,
|
|
||||||
},
|
|
||||||
image: {
|
|
||||||
type: String,
|
|
||||||
default: "",
|
|
||||||
},
|
|
||||||
body: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
isBookMarked: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
module.exports = mongoose.model("Blog", blogSchema);
|
|
|
@ -1,25 +0,0 @@
|
||||||
const mongoose = require("mongoose");
|
|
||||||
const { ObjectId } = mongoose.Schema.Types;
|
|
||||||
const blogSchema = new mongoose.Schema({
|
|
||||||
title: {
|
|
||||||
type: String,
|
|
||||||
require: true,
|
|
||||||
},
|
|
||||||
author: { ref: "Course", type: ObjectId },
|
|
||||||
date: {
|
|
||||||
type: Date,
|
|
||||||
},
|
|
||||||
image: {
|
|
||||||
type: String,
|
|
||||||
default: "",
|
|
||||||
},
|
|
||||||
body: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
isBookMarked: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
module.exports = mongoose.model("Blog", blogSchema);
|
|
|
@ -1,25 +0,0 @@
|
||||||
const mongoose = require("mongoose");
|
|
||||||
const { ObjectId } = mongoose.Schema.Types;
|
|
||||||
const blogSchema = new mongoose.Schema({
|
|
||||||
title: {
|
|
||||||
type: String,
|
|
||||||
require: true,
|
|
||||||
},
|
|
||||||
author: { ref: "User", type: ObjectId },
|
|
||||||
date: {
|
|
||||||
type: Date,
|
|
||||||
},
|
|
||||||
image: {
|
|
||||||
type: String,
|
|
||||||
default: "",
|
|
||||||
},
|
|
||||||
body: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
isBookMarked: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
module.exports = mongoose.model("Blog", blogSchema);
|
|
|
@ -1,25 +0,0 @@
|
||||||
const mongoose = require("mongoose");
|
|
||||||
|
|
||||||
const blogSchema = new mongoose.Schema({
|
|
||||||
title: {
|
|
||||||
type: String,
|
|
||||||
require: true,
|
|
||||||
},
|
|
||||||
author: { ref: "User", type: mongoose.Schema.Types.ObjectId },
|
|
||||||
date: {
|
|
||||||
type: Date,
|
|
||||||
},
|
|
||||||
image: {
|
|
||||||
type: String,
|
|
||||||
default: "",
|
|
||||||
},
|
|
||||||
body: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
isBookMarked: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
module.exports = mongoose.model("Blog", blogSchema);
|
|
|
@ -1,14 +0,0 @@
|
||||||
const express = require("express");
|
|
||||||
const router = express.Router();
|
|
||||||
const BlogController = require("../controllers/blog");
|
|
||||||
const isAuth = require("../middleware/requirelogin");
|
|
||||||
|
|
||||||
router.post("/add-blog", BlogController.addBlog);
|
|
||||||
|
|
||||||
router.get("/get-all-blogs", BlogController.getAllBlogs);
|
|
||||||
|
|
||||||
router.post("/delete-blog/", isAuth, BlogController.deleteBlog);
|
|
||||||
|
|
||||||
router.post("/edit-blog/", isAuth, BlogController.editBlog);
|
|
||||||
|
|
||||||
module.exports = router;
|
|
|
@ -1,14 +0,0 @@
|
||||||
const express = require("express");
|
|
||||||
const router = express.Router();
|
|
||||||
const BlogController = require("../controllers/blog");
|
|
||||||
const isAuth = require("../middleware/requirelogin");
|
|
||||||
|
|
||||||
router.post("/add-blog", BlogController.addBlog);
|
|
||||||
|
|
||||||
router.get("/get-all-blogs", BlogController.getAllBlogs);
|
|
||||||
|
|
||||||
router.post("/delete-blog/", BlogController.deleteBlog);
|
|
||||||
|
|
||||||
router.post("/edit-blog/", BlogController.editBlog);
|
|
||||||
|
|
||||||
module.exports = router;
|
|
Loading…
Reference in New Issue