NodeJ顺序获取数据之间的日期

时间:2019-04-03 06:08:48

标签: node.js orm sequelize.js

这个问题已经被提出,但是不能解决我的问题。

我的database中有两个字段,分别是fromDatetoDate。我要在插入新数据时验证fromDatetoDate

我的意思是,我已经有 fromDate = 2019-04-20 toDate = 2019-04-30 database中的“ strong>”。

现在正尝试将 fromDate 插入为 2019-04-25 ,将 toDate 插入为 2019-04-26

在这种情况下,会抛出类似的错误。

这是我的代码:

controller.js

const db = require('../../config/database');
const CubbersClosure = require('../../model/cubber/cubbersClosure.model')(db.sequelize, db.Sequelize);

exports.cubbersAddClosure = (req, res) =>{
   CubbersClosure.create({
        cubbersId:req.body.cubbersId,
        userId:req.body.userId,
        fromDate:req.body.fromDate,
        toDate:req.body.toDate,
        status:1,
        createdBy:req.body.createdBy,
        updatedBy:req.body.updatedBy
    }).then(closure=>{
        res.status(200).send({status: 'success', resCode:200, msg:'Shop closure date added successfully...!', data:closure});
    }).catch(function (error) {
        res.status(403).send({status: 'error', resCode:200, msg:'Internal Server Error...!', data:error});
    });
}

model.js

module.exports = (sequelize, Sequelize)=>{
    const cubbersAvailability = sequelize.define('cubbersclosure',{
        closureId:{
            type: Sequelize.INTEGER,
            primaryKey:true,
            autoIncrement:true
        },
        cubbersId:{type: Sequelize.INTEGER},
        userId:{type: Sequelize.INTEGER},
        fromDate:{type: Sequelize.STRING},
        toDate:{type: Sequelize.STRING},
        status:{type: Sequelize.INTEGER},
        createdAt:{type: Sequelize.DATE},
        createdBy:{type: Sequelize.INTEGER},
        updatedAt:{type: Sequelize.DATE},
        updatedBy:{type: Sequelize.INTEGER},
    },
    {
        freezeTableName: true
    });
    return cubbersAvailability;
}

数据库: enter image description here

  

注意:在插入新日期之前,我要验证日期之间的此日期是否已经退出...!

0 个答案:

没有答案