Fixed
This commit is contained in:
parent
45b5a2eade
commit
08f0d3a45d
|
@ -1,112 +0,0 @@
|
||||||
const express = require("express");
|
|
||||||
const mongoose = require("mongoose");
|
|
||||||
const bodyparser = require("body-parser");
|
|
||||||
const authRoute = require("./routes/auth");
|
|
||||||
const profileRoute = require("./routes/profile");
|
|
||||||
const paymentRoute = require("./routes/payment");
|
|
||||||
const courseRoute = require("./routes/course");
|
|
||||||
const couponRoute = require("./routes/Coupon");
|
|
||||||
const queryRoute = require("./routes/query");
|
|
||||||
const adminRoute = require("./routes/admin");
|
|
||||||
const blogRouter = require("./routes/blog");
|
|
||||||
const port = process.env.PORT || 5000;
|
|
||||||
const cors = require("cors");
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
//const passport = require('passport');
|
|
||||||
//const cookieSession = require('cookie-session') ;
|
|
||||||
//require('./passport-setup') ;
|
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
>>>>>>> ef4c9b6a526e0ef10b94f271654809ce636d8ab0
|
|
||||||
const MONGO_URI = `mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@cluster0.dqxva.mongodb.net/${process.env.MONGO_DEFAULT_DATABASE}?retryWrites=true&w=majority`;
|
|
||||||
|
|
||||||
app.use(cors());
|
|
||||||
app.use(bodyparser.json());
|
|
||||||
|
|
||||||
// app.use(cookieSession({
|
|
||||||
// name: 'test-session',
|
|
||||||
// keys: ['key1', 'key2']
|
|
||||||
// }))
|
|
||||||
|
|
||||||
// const isLoggedIn = (req , res , next) => {
|
|
||||||
// if(req.user)
|
|
||||||
// {
|
|
||||||
// next()
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// res.json({
|
|
||||||
// error : "No user"
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// app.use(passport.initialize());
|
|
||||||
// app.use(passport.session());
|
|
||||||
|
|
||||||
// app.get('/failed' , (req , res) => {
|
|
||||||
// res.json({
|
|
||||||
// error : "You have failed to login"
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
|
|
||||||
// app.get('/' , (req , res) => {
|
|
||||||
// console.log('you are not logged in');
|
|
||||||
|
|
||||||
// })
|
|
||||||
|
|
||||||
// app.get('/good' ,isLoggedIn , (req , res) => {
|
|
||||||
// res.json({
|
|
||||||
// message:"success" ,
|
|
||||||
// user : req.user
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
|
|
||||||
// app.get('/auth/google',
|
|
||||||
// passport.authenticate('google', { scope: ['profile' , 'email'] }));
|
|
||||||
|
|
||||||
// app.get('/auth/google/callback',
|
|
||||||
// passport.authenticate('google', { failureRedirect: '/failed' }),
|
|
||||||
// function(req, res) {
|
|
||||||
// res.redirect('/good');
|
|
||||||
// });
|
|
||||||
|
|
||||||
// app.get('/logout', (req , res) => {
|
|
||||||
// req.session = null ;
|
|
||||||
// req.logout() ;
|
|
||||||
// res.redirect('/') ;
|
|
||||||
// })
|
|
||||||
mongoose
|
|
||||||
.connect(MONGO_URI, {
|
|
||||||
useNewUrlParser: true,
|
|
||||||
useUnifiedTopology: true,
|
|
||||||
useFindAndModify: false,
|
|
||||||
})
|
|
||||||
.then((result) => {
|
|
||||||
console.log("connected");
|
|
||||||
app.listen(port, () => {
|
|
||||||
console.log("server is running on port", port);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
app.use(authRoute);
|
|
||||||
|
|
||||||
app.use(profileRoute);
|
|
||||||
|
|
||||||
app.use(paymentRoute);
|
|
||||||
|
|
||||||
app.use(courseRoute);
|
|
||||||
|
|
||||||
app.use(adminRoute);
|
|
||||||
|
|
||||||
app.use(couponRoute);
|
|
||||||
|
|
||||||
app.use(blogRouter);
|
|
||||||
|
|
||||||
app.use(queryRoute);
|
|
|
@ -1,107 +0,0 @@
|
||||||
const express = require("express");
|
|
||||||
const mongoose = require("mongoose");
|
|
||||||
const bodyparser = require("body-parser");
|
|
||||||
const authRoute = require("./routes/auth");
|
|
||||||
const profileRoute = require("./routes/profile");
|
|
||||||
const paymentRoute = require("./routes/payment");
|
|
||||||
const courseRoute = require("./routes/course");
|
|
||||||
const couponRoute = require("./routes/Coupon");
|
|
||||||
const queryRoute = require("./routes/query");
|
|
||||||
const adminRoute = require("./routes/admin");
|
|
||||||
const blogRouter = require("./routes/blog");
|
|
||||||
const port = process.env.PORT || 5000;
|
|
||||||
const cors = require("cors");
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
//const passport = require('passport');
|
|
||||||
//const cookieSession = require('cookie-session') ;
|
|
||||||
//require('./passport-setup') ;
|
|
||||||
|
|
||||||
const MONGO_URI = `mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@cluster0.dqxva.mongodb.net/${process.env.MONGO_DEFAULT_DATABASE}?retryWrites=true&w=majority`;
|
|
||||||
|
|
||||||
app.use(cors());
|
|
||||||
app.use(bodyparser.json());
|
|
||||||
|
|
||||||
// app.use(cookieSession({
|
|
||||||
// name: 'test-session',
|
|
||||||
// keys: ['key1', 'key2']
|
|
||||||
// }))
|
|
||||||
|
|
||||||
// const isLoggedIn = (req , res , next) => {
|
|
||||||
// if(req.user)
|
|
||||||
// {
|
|
||||||
// next()
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// res.json({
|
|
||||||
// error : "No user"
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// app.use(passport.initialize());
|
|
||||||
// app.use(passport.session());
|
|
||||||
|
|
||||||
// app.get('/failed' , (req , res) => {
|
|
||||||
// res.json({
|
|
||||||
// error : "You have failed to login"
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
|
|
||||||
// app.get('/' , (req , res) => {
|
|
||||||
// console.log('you are not logged in');
|
|
||||||
|
|
||||||
// })
|
|
||||||
|
|
||||||
// app.get('/good' ,isLoggedIn , (req , res) => {
|
|
||||||
// res.json({
|
|
||||||
// message:"success" ,
|
|
||||||
// user : req.user
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
|
|
||||||
// app.get('/auth/google',
|
|
||||||
// passport.authenticate('google', { scope: ['profile' , 'email'] }));
|
|
||||||
|
|
||||||
// app.get('/auth/google/callback',
|
|
||||||
// passport.authenticate('google', { failureRedirect: '/failed' }),
|
|
||||||
// function(req, res) {
|
|
||||||
// res.redirect('/good');
|
|
||||||
// });
|
|
||||||
|
|
||||||
// app.get('/logout', (req , res) => {
|
|
||||||
// req.session = null ;
|
|
||||||
// req.logout() ;
|
|
||||||
// res.redirect('/') ;
|
|
||||||
// })
|
|
||||||
mongoose
|
|
||||||
.connect(MONGO_URI, {
|
|
||||||
useNewUrlParser: true,
|
|
||||||
useUnifiedTopology: true,
|
|
||||||
useFindAndModify: false,
|
|
||||||
})
|
|
||||||
.then((result) => {
|
|
||||||
console.log("connected");
|
|
||||||
app.listen(port, () => {
|
|
||||||
console.log("server is running on port", port);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
app.use(authRoute);
|
|
||||||
|
|
||||||
app.use(profileRoute);
|
|
||||||
|
|
||||||
app.use(paymentRoute);
|
|
||||||
|
|
||||||
app.use(courseRoute);
|
|
||||||
|
|
||||||
app.use(adminRoute);
|
|
||||||
|
|
||||||
app.use(couponRoute);
|
|
||||||
|
|
||||||
app.use(blogRouter);
|
|
||||||
|
|
||||||
app.use(queryRoute);
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,103 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,106 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,106 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,106 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,105 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,105 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,105 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,105 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,105 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,105 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,105 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,105 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,106 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,106 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,106 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,105 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,106 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,106 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,106 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,106 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,104 @@
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,27 @@
|
||||||
|
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);
|
|
@ -0,0 +1,28 @@
|
||||||
|
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);
|
|
@ -0,0 +1,25 @@
|
||||||
|
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);
|
|
@ -0,0 +1,25 @@
|
||||||
|
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);
|
|
@ -0,0 +1,25 @@
|
||||||
|
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);
|
|
@ -0,0 +1,14 @@
|
||||||
|
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;
|
|
@ -0,0 +1,14 @@
|
||||||
|
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;
|
|
@ -1,6 +1,6 @@
|
||||||
const { log } = require("handlebars");
|
const { log } = require("handlebars");
|
||||||
const Blog = require("../models/Blog");
|
const Blog = require("../models/Blog");
|
||||||
const Course = require("../models/Course");
|
const User = require("../models/User");
|
||||||
|
|
||||||
module.exports.getAllBlogs = async (req, res, next) => {
|
module.exports.getAllBlogs = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
|
@ -21,7 +21,7 @@ module.exports.getAllBlogs = async (req, res, next) => {
|
||||||
module.exports.addBlog = async (req, res, next) => {
|
module.exports.addBlog = async (req, res, next) => {
|
||||||
const { _id, title, body, image } = req.body; //_id is of user from frontend who is adding the blog.
|
const { _id, title, body, image } = req.body; //_id is of user from frontend who is adding the blog.
|
||||||
try {
|
try {
|
||||||
let course = await Course.find({ _id });
|
let user = await User.findById({ _id });
|
||||||
if (!title) {
|
if (!title) {
|
||||||
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
res.status(422).json({ message: "Please, Add Title of the Blog" });
|
||||||
return;
|
return;
|
||||||
|
@ -30,12 +30,13 @@ module.exports.addBlog = async (req, res, next) => {
|
||||||
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
res.status(422).json({ message: "Please, Add Body of the Blog" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (course) {
|
if (user) {
|
||||||
let blog = new Blog({
|
let blog = new Blog({
|
||||||
title,
|
title,
|
||||||
body,
|
body,
|
||||||
image,
|
image,
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
|
author: user,
|
||||||
});
|
});
|
||||||
await blog.save();
|
await blog.save();
|
||||||
res.json({ message: "Blog Saved Successfully!" });
|
res.json({ message: "Blog Saved Successfully!" });
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
const mongoose = require("mongoose");
|
const mongoose = require("mongoose");
|
||||||
|
|
||||||
const blogSchema = new mongoose.Schema({
|
const blogSchema = new mongoose.Schema({
|
||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
require: true,
|
require: true,
|
||||||
},
|
},
|
||||||
author: {
|
author: { ref: "User", type: mongoose.Schema.Types.ObjectId },
|
||||||
type: String,
|
|
||||||
ref: "Course",
|
|
||||||
},
|
|
||||||
date: {
|
date: {
|
||||||
type: Date,
|
type: Date,
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,8 +7,8 @@ router.post("/add-blog", BlogController.addBlog);
|
||||||
|
|
||||||
router.get("/get-all-blogs", BlogController.getAllBlogs);
|
router.get("/get-all-blogs", BlogController.getAllBlogs);
|
||||||
|
|
||||||
router.post("/delete-blog/", isAuth, BlogController.deleteBlog);
|
router.post("/delete-blog/", BlogController.deleteBlog);
|
||||||
|
|
||||||
router.post("/edit-blog/", isAuth, BlogController.editBlog);
|
router.post("/edit-blog/", BlogController.editBlog);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
Loading…
Reference in New Issue