Compare commits

..

No commits in common. "bf8987242bb014d01f806648b886bb0e5275c9be" and "c7fa40266325d2a65be8d2e16f48c09cf94a6932" have entirely different histories.

2 changed files with 19 additions and 16 deletions

View File

@ -17,8 +17,8 @@ export abstract class BaseDataService<Entity> {
entityTarget: EntityTarget<Entity>, entityTarget: EntityTarget<Entity>,
entity: Entity, entity: Entity,
): Promise<Entity> { ): Promise<Entity> {
// const newEntity = this.repository.create(entityTarget, entity); const newEntity = queryRunner.manager.create(entityTarget, entity);
return await this.repository.save(entity); return await queryRunner.manager.save(newEntity);
} }
async createMany( async createMany(
@ -26,8 +26,8 @@ export abstract class BaseDataService<Entity> {
entityTarget: EntityTarget<Entity>, entityTarget: EntityTarget<Entity>,
entity: Entity[], entity: Entity[],
): Promise<Entity[]> { ): Promise<Entity[]> {
// const newEntity = this.repository.create(entityTarget, entity); const newEntity = queryRunner.manager.create(entityTarget, entity);
return await this.repository.save(entity); return await queryRunner.manager.save(newEntity);
} }
async createBatch( async createBatch(
@ -35,8 +35,8 @@ export abstract class BaseDataService<Entity> {
entityTarget: EntityTarget<Entity>, entityTarget: EntityTarget<Entity>,
entity: Entity[], entity: Entity[],
): Promise<Entity[]> { ): Promise<Entity[]> {
// const newEntity = this.repository.create(entityTarget, entity); const newEntity = queryRunner.manager.create(entityTarget, entity);
return await this.repository.save(entity); return await queryRunner.manager.save(newEntity);
} }
async update( async update(
@ -45,13 +45,13 @@ export abstract class BaseDataService<Entity> {
filterUpdate: any, filterUpdate: any,
entity: Entity, entity: Entity,
): Promise<Entity> { ): Promise<Entity> {
const newEntity = await this.repository.findOne({ const newEntity = await queryRunner.manager.findOne(entityTarget, {
where: filterUpdate, where: filterUpdate,
}); });
if (!newEntity) throw new Error('Data not found!'); if (!newEntity) throw new Error('Data not found!');
Object.assign(newEntity, entity); Object.assign(newEntity, entity);
return await this.repository.save(newEntity); return await queryRunner.manager.save(newEntity);
} }
async deleteById( async deleteById(
@ -59,7 +59,7 @@ export abstract class BaseDataService<Entity> {
entityTarget: EntityTarget<Entity>, entityTarget: EntityTarget<Entity>,
id: string, id: string,
): Promise<void> { ): Promise<void> {
await this.repository.delete(id); await queryRunner.manager.delete(entityTarget, { id });
} }
async deleteByOptions( async deleteByOptions(
@ -67,8 +67,11 @@ export abstract class BaseDataService<Entity> {
entityTarget: EntityTarget<Entity>, entityTarget: EntityTarget<Entity>,
findManyOptions: FindManyOptions<Entity>, findManyOptions: FindManyOptions<Entity>,
): Promise<void> { ): Promise<void> {
const datas = await this.repository.find(findManyOptions); const datas = await queryRunner.manager.find(entityTarget, findManyOptions);
await this.repository.delete(datas?.map((item) => item['id'])); await queryRunner.manager.delete(
entityTarget,
datas?.map((item) => item['id']),
);
} }
async getOneByOptions(findOneOptions): Promise<Entity> { async getOneByOptions(findOneOptions): Promise<Entity> {

View File

@ -60,7 +60,7 @@ export abstract class BaseManager {
try { try {
this.setUser(); this.setUser();
this.queryRunner.startTransaction(); // this.queryRunner.startTransaction();
this.baseLog.verbose('prepareData'); this.baseLog.verbose('prepareData');
await this.prepareData(); await this.prepareData();
@ -80,13 +80,13 @@ export abstract class BaseManager {
this.baseLog.verbose('afterProcess'); this.baseLog.verbose('afterProcess');
await this.afterProcess(); await this.afterProcess();
this.baseLog.verbose('commitTransaction'); // this.baseLog.verbose('commitTransaction');
await this.queryRunner.commitTransaction(); // await this.queryRunner.commitTransaction();
// await this.queryRunner.release();
} catch (e) { } catch (e) {
if (e.response) throw new Error(JSON.stringify(e.response)); if (e.response) throw new Error(JSON.stringify(e.response));
else throw new Error(e.message); else throw new Error(e.message);
} finally {
await this.queryRunner.release();
} }
} }