Guest User

Untitled

a guest
Jan 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. router.post('/admin/editFront', isLoggedIn, (req, res, next) => {
  2. req.checkBody('title', 'Title is require').notEmpty();
  3. req.checkBody('aboutUs', 'About us section is require').notEmpty();
  4. req.checkBody('email', 'Check email again').notEmpty().isEmail();
  5.  
  6. let errors = req.validationErrors();
  7. if(errors) {
  8. req.flash('error_msg', errors.msg);
  9. console.log(errors);
  10. }
  11.  
  12. let cube = ({
  13. title: req.body.cubeTitle,
  14. img: req.body.cubeImg,
  15. info: req.body.cubeInfo
  16. })
  17.  
  18. let front = new FrontInfo();
  19. front.title = req.body.title;
  20. front.aboutUs = req.body.aboutUs;
  21. front.email = req.body.email;
  22. front.phone = req.body.phone;
  23. front.cube.push(cube);
  24. // front.socialNet.push(req.body.social);
  25.  
  26. console.log(front);
  27.  
  28. FrontInfo.findOneAndUpdate({email: req.body.email}, front, { upsert: true }, (err, doc) => {
  29. if(err) console.log(err);
  30. else {
  31. req.flash('success', doc);
  32. res.redirect('/editFront');
  33. }
  34. });
  35. });
  36.  
  37. let cube = new Schema({
  38. title: { type: String },
  39. img: { type: String },
  40. info: { type: String }
  41. });
  42.  
  43. let socialNet = new Schema({
  44. title: { type: String, required: true },
  45. link: { type: String, required: true },
  46. icon: { type: String, required: true }
  47. });
  48.  
  49. let FrontInfo = new Schema({
  50. title: { type: String, required: true },
  51. aboutUs: {type: String, required: true},
  52. phone: {type: String, minlength: 9, required: true},
  53. email: {type: String, required: true},
  54. cube: {type: [cube], default: []},
  55. updateDate: {type: Date, default: Date.now}
  56. });
Add Comment
Please, Sign In to add comment