Sequqlize how to insert data in sequelize using node i have done almost every thing but still getting error

Posted 1 year ago by asad98iftikhar

//POST ADD page router.post('/add-page',function(req,res){

req.checkBody('title','Title must have a body.').notEmpty(); req.checkBody('content','Content must have a body.').notEmpty();

var title=req.body.title; var slug=req.body.slug.replace(/\s+/g, '-').toLowerCase(); if(slug==" ")slug=title.replace(/\s+/g, '-').toLowerCase();

var content=req.body.content;

var errors=req.validationErrors();

if(errors){ res.render('admin/add_page',{ errors:errors, title:title, slug:slug, content:content }); } else{ Page.findOne({slug:slug},function(err,page){ if(page){ req.flash('danger','Page slug Already Exist,'); res.render('admin/add_page',{

        title:title,
        slug:slug,
        content:content
      });
    }
    else{
        var page=new Page({
          title:title,
          slug:slug,
          content:content,
          sorting:0
        });









        page.save(function(err){
          if(err) return console.log(err);

          req.flash('success','Page Added Successfully!!');
          res.redirect('/admin/pages');
        });
    }

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.