Bookshelf.js and Knex.js

0

I have created a database with fields that can not be null, when making an insertion or an update using the "forge" method of bookshelf.js, create the records even if the information is not sent, how can I prevent If the fields do not have information do not insert in the bd?

Obviously with conditionals it can be done, but I mean it is that in the process of insertion there must be some error message that says that such a field can not be null.

let store = (req, res) => {
    let data = req.body;

    User.forge({
        name : data.name,
        surname : data.surname,
        email : data.email,
        password : data.password,
        role : data.role
    }).save()
    .then((user) => {
        return res.status(201).send({message:'User created', user})
    }).catch((err) => {
        return res.status(500).send({message : 'Error '});
    });
}
    
asked by Sergio Aguirre Romero 08.05.2018 в 06:13
source

0 answers