Compare commits
7 Commits
6632222c4b
...
dc6476a66f
Author | SHA1 | Date |
---|---|---|
|
dc6476a66f | |
|
4a9ca5eb5b | |
|
e1004b3843 | |
|
bf8987242b | |
|
57f2700c94 | |
|
c7fa402663 | |
|
d333ba03a7 |
|
@ -17,8 +17,8 @@ export abstract class BaseDataService<Entity> {
|
|||
entityTarget: EntityTarget<Entity>,
|
||||
entity: Entity,
|
||||
): Promise<Entity> {
|
||||
const newEntity = queryRunner.manager.create(entityTarget, entity);
|
||||
return await queryRunner.manager.save(newEntity);
|
||||
// const newEntity = this.repository.create(entityTarget, entity);
|
||||
return await this.repository.save(entity);
|
||||
}
|
||||
|
||||
async createMany(
|
||||
|
@ -26,8 +26,8 @@ export abstract class BaseDataService<Entity> {
|
|||
entityTarget: EntityTarget<Entity>,
|
||||
entity: Entity[],
|
||||
): Promise<Entity[]> {
|
||||
const newEntity = queryRunner.manager.create(entityTarget, entity);
|
||||
return await queryRunner.manager.save(newEntity);
|
||||
// const newEntity = this.repository.create(entityTarget, entity);
|
||||
return await this.repository.save(entity);
|
||||
}
|
||||
|
||||
async createBatch(
|
||||
|
@ -35,8 +35,8 @@ export abstract class BaseDataService<Entity> {
|
|||
entityTarget: EntityTarget<Entity>,
|
||||
entity: Entity[],
|
||||
): Promise<Entity[]> {
|
||||
const newEntity = queryRunner.manager.create(entityTarget, entity);
|
||||
return await queryRunner.manager.save(newEntity);
|
||||
// const newEntity = this.repository.create(entityTarget, entity);
|
||||
return await this.repository.save(entity);
|
||||
}
|
||||
|
||||
async update(
|
||||
|
@ -45,13 +45,13 @@ export abstract class BaseDataService<Entity> {
|
|||
filterUpdate: any,
|
||||
entity: Entity,
|
||||
): Promise<Entity> {
|
||||
const newEntity = await queryRunner.manager.findOne(entityTarget, {
|
||||
const newEntity = await this.repository.findOne({
|
||||
where: filterUpdate,
|
||||
});
|
||||
|
||||
if (!newEntity) throw new Error('Data not found!');
|
||||
Object.assign(newEntity, entity);
|
||||
return await queryRunner.manager.save(newEntity);
|
||||
return await this.repository.save(newEntity);
|
||||
}
|
||||
|
||||
async deleteById(
|
||||
|
@ -59,7 +59,7 @@ export abstract class BaseDataService<Entity> {
|
|||
entityTarget: EntityTarget<Entity>,
|
||||
id: string,
|
||||
): Promise<void> {
|
||||
await queryRunner.manager.delete(entityTarget, { id });
|
||||
await this.repository.delete(id);
|
||||
}
|
||||
|
||||
async deleteByOptions(
|
||||
|
@ -67,11 +67,8 @@ export abstract class BaseDataService<Entity> {
|
|||
entityTarget: EntityTarget<Entity>,
|
||||
findManyOptions: FindManyOptions<Entity>,
|
||||
): Promise<void> {
|
||||
const datas = await queryRunner.manager.find(entityTarget, findManyOptions);
|
||||
await queryRunner.manager.delete(
|
||||
entityTarget,
|
||||
datas?.map((item) => item['id']),
|
||||
);
|
||||
const datas = await this.repository.find(findManyOptions);
|
||||
await this.repository.delete(datas?.map((item) => item['id']));
|
||||
}
|
||||
|
||||
async getOneByOptions(findOneOptions): Promise<Entity> {
|
||||
|
|
|
@ -60,7 +60,7 @@ export abstract class BaseManager {
|
|||
try {
|
||||
this.setUser();
|
||||
|
||||
// this.queryRunner.startTransaction();
|
||||
this.queryRunner.startTransaction();
|
||||
this.baseLog.verbose('prepareData');
|
||||
await this.prepareData();
|
||||
|
||||
|
@ -80,13 +80,13 @@ export abstract class BaseManager {
|
|||
this.baseLog.verbose('afterProcess');
|
||||
await this.afterProcess();
|
||||
|
||||
// this.baseLog.verbose('commitTransaction');
|
||||
// await this.queryRunner.commitTransaction();
|
||||
|
||||
// await this.queryRunner.release();
|
||||
this.baseLog.verbose('commitTransaction');
|
||||
await this.queryRunner.commitTransaction();
|
||||
} catch (e) {
|
||||
if (e.response) throw new Error(JSON.stringify(e.response));
|
||||
else throw new Error(e.message);
|
||||
} finally {
|
||||
await this.queryRunner.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,10 +17,17 @@ import { STATUS } from 'src/core/strings/constants/base.constants';
|
|||
@Injectable()
|
||||
export class BatchCancelRefundManager extends BaseBatchUpdateStatusManager<RefundEntity> {
|
||||
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({
|
||||
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',
|
||||
});
|
||||
}
|
||||
|
|
|
@ -20,10 +20,17 @@ export class CancelRefundManager extends BaseUpdateStatusManager<RefundEntity> {
|
|||
}
|
||||
|
||||
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({
|
||||
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',
|
||||
});
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ export class UpdateTransactionManager extends BaseUpdateManager<TransactionEntit
|
|||
return [
|
||||
{
|
||||
topic: TransactionUpdatedEvent,
|
||||
data: this.data,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue