Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.post('/admin/editFront', isLoggedIn, (req, res, next) => {
- req.checkBody('title', 'Title is require').notEmpty();
- req.checkBody('aboutUs', 'About us section is require').notEmpty();
- req.checkBody('email', 'Check email again').notEmpty().isEmail();
- let errors = req.validationErrors();
- if(errors) {
- req.flash('error_msg', errors.msg);
- console.log(errors);
- }
- let cube = ({
- title: req.body.cubeTitle,
- img: req.body.cubeImg,
- info: req.body.cubeInfo
- })
- let front = new FrontInfo();
- front.title = req.body.title;
- front.aboutUs = req.body.aboutUs;
- front.email = req.body.email;
- front.phone = req.body.phone;
- front.cube.push(cube);
- // front.socialNet.push(req.body.social);
- console.log(front);
- FrontInfo.findOneAndUpdate({email: req.body.email}, front, { upsert: true }, (err, doc) => {
- if(err) console.log(err);
- else {
- req.flash('success', doc);
- res.redirect('/editFront');
- }
- });
- });
- let cube = new Schema({
- title: { type: String },
- img: { type: String },
- info: { type: String }
- });
- let socialNet = new Schema({
- title: { type: String, required: true },
- link: { type: String, required: true },
- icon: { type: String, required: true }
- });
- let FrontInfo = new Schema({
- title: { type: String, required: true },
- aboutUs: {type: String, required: true},
- phone: {type: String, minlength: 9, required: true},
- email: {type: String, required: true},
- cube: {type: [cube], default: []},
- updateDate: {type: Date, default: Date.now}
- });
Add Comment
Please, Sign In to add comment