0
In the code below I make a query and bring the contracts that are concluded or not, according to the parameter concluido
(0 or 1).
How do I bring this consultation all contracts when the parameter value is not passed concluido
by requisition?
exports.read = function(req, res) {
var concluido = parseInt(req.query.concluido);
knex.select()
.from('contrato as c')
.innerJoin('empresa as e', 'e.idempresa', 'c.idempresa')
.where('c.concluido', concluido)
.then(function (result) {
return res.status(200).json(result);
})
.catch(function (err) {
return res.status(400).json(err);
});
}
I currently have two knex functions that are called according to the conditions, but as I have several parameters I will have to create several functions, I believe that is not the correct way.
Note: it can be some example in SQL itself.