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