Compare commits

...

7 Commits

5 changed files with 34 additions and 24 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 = 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> {

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();
} }
} }

View File

@ -17,10 +17,17 @@ import { STATUS } from 'src/core/strings/constants/base.constants';
@Injectable() @Injectable()
export class BatchCancelRefundManager extends BaseBatchUpdateStatusManager<RefundEntity> { export class BatchCancelRefundManager extends BaseBatchUpdateStatusManager<RefundEntity> {
validateData(data: RefundEntity): Promise<void> { validateData(data: RefundEntity): Promise<void> {
if (![STATUS.REFUNDED, STATUS.PENDING].includes(data.status)) { if (
![
STATUS.REFUNDED,
STATUS.PENDING,
STATUS.PROCESS_REFUND,
STATUS.PARTIAL_REFUND,
].includes(data.status)
) {
throw new UnprocessableEntityException({ throw new UnprocessableEntityException({
statusCode: HttpStatus.UNPROCESSABLE_ENTITY, statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
message: `Failed! only data with status ${STATUS.REFUNDED} and ${STATUS.PENDING} can be cancelled`, message: `Failed! only data with status ${STATUS.REFUNDED}, ${STATUS.PROCESS_REFUND} , ${STATUS.PARTIAL_REFUND} and ${STATUS.PENDING} can be cancelled`,
error: 'Unprocessable Entity', error: 'Unprocessable Entity',
}); });
} }

View File

@ -20,10 +20,17 @@ export class CancelRefundManager extends BaseUpdateStatusManager<RefundEntity> {
} }
async validateProcess(): Promise<void> { async validateProcess(): Promise<void> {
if (![STATUS.REFUNDED, STATUS.PENDING].includes(this.data.status)) { if (
![
STATUS.REFUNDED,
STATUS.PENDING,
STATUS.PROCESS_REFUND,
STATUS.PARTIAL_REFUND,
].includes(this.data.status)
) {
throw new UnprocessableEntityException({ throw new UnprocessableEntityException({
statusCode: HttpStatus.UNPROCESSABLE_ENTITY, statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
message: `Failed! only data with status ${STATUS.REFUNDED} and ${STATUS.PENDING} can be cancelled`, message: `Failed! only data with status ${STATUS.REFUNDED}, ${STATUS.PROCESS_REFUND} , ${STATUS.PARTIAL_REFUND} and ${STATUS.PENDING} can be cancelled`,
error: 'Unprocessable Entity', error: 'Unprocessable Entity',
}); });
} }

View File

@ -42,7 +42,6 @@ export class UpdateTransactionManager extends BaseUpdateManager<TransactionEntit
return [ return [
{ {
topic: TransactionUpdatedEvent, topic: TransactionUpdatedEvent,
data: this.data,
}, },
]; ];
} }