I need to run a patch (or an update) in Objection.js, based on a condition. I have this code:
if (leavenMachine.ping == true){
MachinesInit.query()
.patch({status: 'OK', online:"yes"})
.where('machine', 'leaven machine')
.where('type', 'M');
}else {
MachinesInit.query()
.patch({status: 'OK'})
.where('machine', 'leaven machine')
.where('type', 'M');
}
I need to refactor it so that I don't need two queries (one inside the if condition and the second inside the else), but just one, embedding the condition inside the patch method. Is it possible? How can I do?