manual rollback

This commit is contained in:
Pierre Noël 2022-12-02 18:09:30 +01:00
parent 12f3bb794c
commit ded213f13f

View File

@ -223,6 +223,7 @@ const createEntityManager = (db) => {
await trx.commit(); await trx.commit();
} catch (e) { } catch (e) {
await trx.rollback(); await trx.rollback();
await this.createQueryBuilder(uid).where({ id }).delete().execute();
throw e; throw e;
} }
@ -281,7 +282,11 @@ const createEntityManager = (db) => {
throw new Error('Update requires a where parameter'); throw new Error('Update requires a where parameter');
} }
const entity = await this.createQueryBuilder(uid).select('id').where(where).first().execute(); const entity = await this.createQueryBuilder(uid)
.select('*')
.where(where)
.first()
.execute({ mapResults: false });
if (!entity) { if (!entity) {
return null; return null;
@ -298,10 +303,10 @@ const createEntityManager = (db) => {
const trx = await strapi.db.transaction(); const trx = await strapi.db.transaction();
try { try {
await this.updateRelations(uid, id, data, { transaction: trx }); await this.updateRelations(uid, id, data, { transaction: trx });
await trx.commit(); await trx.commit();
} catch (e) { } catch (e) {
await trx.rollback(); await trx.rollback();
await this.createQueryBuilder(uid).where({ id }).update(entity).execute();
throw e; throw e;
} }