fix: call rollback in catch
This commit is contained in:
parent
a0fc7a17d1
commit
0ef730d7e4
@ -255,6 +255,7 @@ export async function create(ctx: Context, next: Next) {
|
|||||||
const transaction = await ctx.db.sequelize.transaction();
|
const transaction = await ctx.db.sequelize.transaction();
|
||||||
const options = { transaction, context: ctx };
|
const options = { transaction, context: ctx };
|
||||||
let model: Model;
|
let model: Model;
|
||||||
|
try {
|
||||||
if (associated && resourceField) {
|
if (associated && resourceField) {
|
||||||
const AssociatedModel = ctx.db.getModel(associatedName);
|
const AssociatedModel = ctx.db.getModel(associatedName);
|
||||||
if (!(associated instanceof AssociatedModel)) {
|
if (!(associated instanceof AssociatedModel)) {
|
||||||
@ -270,6 +271,10 @@ export async function create(ctx: Context, next: Next) {
|
|||||||
await transaction.commit();
|
await transaction.commit();
|
||||||
ctx.body = model;
|
ctx.body = model;
|
||||||
await next();
|
await next();
|
||||||
|
} catch (error) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user