transtaction commits on several endpoints
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
2bfc6a5987
commit
5a448234d6
|
@ -33,6 +33,7 @@ module.exports = Self => {
|
|||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const isEditable = await Self.app.models.Order.isEditable(params.orderFk, myOptions);
|
||||
|
||||
if (!isEditable)
|
||||
|
@ -50,6 +51,12 @@ module.exports = Self => {
|
|||
}
|
||||
await Promise.all(promises);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -33,6 +33,7 @@ module.exports = Self => {
|
|||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!params.rows || !params.rows.length)
|
||||
throw new UserError('There is nothing to delete');
|
||||
|
||||
|
@ -45,6 +46,14 @@ module.exports = Self => {
|
|||
for (let i = 0; i < params.rows.length; i++)
|
||||
promises.push(Self.app.models.OrderRow.destroyById(params.rows[i], myOptions));
|
||||
|
||||
return Promise.all(promises);
|
||||
const deletions = await Promise.all(promises);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return deletions;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -44,6 +44,7 @@ module.exports = Self => {
|
|||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const address = await Self.app.models.Address.findOne({
|
||||
where: {id: addressId},
|
||||
fields: ['clientFk'],
|
||||
|
@ -71,6 +72,12 @@ module.exports = Self => {
|
|||
'SALIX'
|
||||
], myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return result[0].vOrderId;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -30,6 +30,7 @@ module.exports = Self => {
|
|||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const ticket = await Self.app.models.Ticket.findOne({
|
||||
where: {id: ticketFk}
|
||||
}, myOptions);
|
||||
|
@ -40,6 +41,12 @@ module.exports = Self => {
|
|||
|
||||
const orderID = await Self.app.models.Order.new(landed, addressFk, agencyModeFk, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return orderID;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -43,7 +43,7 @@ module.exports = Self => {
|
|||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const order = await models.Order.findById(id, null, myOptions);
|
||||
const orderRows = await models.OrderRow.find({where: {orderFk: id}}, myOptions);
|
||||
|
||||
|
@ -60,6 +60,12 @@ module.exports = Self => {
|
|||
if (Object.keys(updateParams).length)
|
||||
await order.updateAttributes(updateParams, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return order;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue