Reputation: 43
The update is not working, but the promise is returning success. I think it may be with the Where in the sequelize query not finding the value from the array of objects productsCodeArr.
const orderid = req.params.orderid
const productsCodeArr = convertedInputs.map(code => {
return ({
id: code.id,
picked: code.picked,
notPicked: code.notPicked
});
})
if(productsCodeArr) {
db.Detallepedido.update({
pickeado: productsCodeArr.picked,
nopickeado: productsCodeArr.notPicked
},
{
where: {
pedido_id: orderid,
producto_id: productsCodeArr.id
}
})
.then(() => {
console.log('Success!');
}})
.catch(reason => {
console.log(reason);
})
Upvotes: 1
Views: 117
Reputation: 43
I did it! I used Promise.all with a map of the array.
Promise.all(productsCodeArr.map(object=>{
return db.Detallepedido.update({
pickeado: object.picked,
nopickeado: object.notPicked
},
{
where: {
pedido_id: orderid,
producto_id: object.id
}
})}))
Upvotes: 2