Merge pull request 'fix: change query runner to repository from base manager' (#41) from fix/base-query into development
continuous-integration/drone/tag Build is passing
Details
continuous-integration/drone/tag Build is passing
Details
Reviewed-on: #41pull/44/head devel_11.0.0
commit
bf8987242b
|
@ -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 = queryRunner.manager.create(entityTarget, entity);
|
// const newEntity = this.repository.create(entityTarget, entity);
|
||||||
return await queryRunner.manager.save(newEntity);
|
return await this.repository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = queryRunner.manager.create(entityTarget, entity);
|
// const newEntity = this.repository.create(entityTarget, entity);
|
||||||
return await queryRunner.manager.save(newEntity);
|
return await this.repository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = queryRunner.manager.create(entityTarget, entity);
|
// const newEntity = this.repository.create(entityTarget, entity);
|
||||||
return await queryRunner.manager.save(newEntity);
|
return await this.repository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 queryRunner.manager.findOne(entityTarget, {
|
const newEntity = await this.repository.findOne({
|
||||||
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 queryRunner.manager.save(newEntity);
|
return await this.repository.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 queryRunner.manager.delete(entityTarget, { id });
|
await this.repository.delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteByOptions(
|
async deleteByOptions(
|
||||||
|
@ -67,11 +67,8 @@ export abstract class BaseDataService<Entity> {
|
||||||
entityTarget: EntityTarget<Entity>,
|
entityTarget: EntityTarget<Entity>,
|
||||||
findManyOptions: FindManyOptions<Entity>,
|
findManyOptions: FindManyOptions<Entity>,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const datas = await queryRunner.manager.find(entityTarget, findManyOptions);
|
const datas = await this.repository.find(findManyOptions);
|
||||||
await queryRunner.manager.delete(
|
await this.repository.delete(datas?.map((item) => item['id']));
|
||||||
entityTarget,
|
|
||||||
datas?.map((item) => item['id']),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOneByOptions(findOneOptions): Promise<Entity> {
|
async getOneByOptions(findOneOptions): Promise<Entity> {
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue