pos-be/src/modules/transaction/refund/domain/usecases/managers/create-refund.manager.ts

55 lines
1.4 KiB
TypeScript

import {
HttpStatus,
Injectable,
UnprocessableEntityException,
} from '@nestjs/common';
import {
EventTopics,
columnUniques,
validateRelations,
} from 'src/core/strings/constants/interface.constants';
import { RefundEntity } from '../../entities/refund.entity';
import { RefundModel } from '../../../data/models/refund.model';
import { BaseCreateManager } from 'src/core/modules/domain/usecase/managers/base-create.manager';
import { RefundCreatedEvent } from '../../entities/event/refund-created.event';
import { STATUS } from 'src/core/strings/constants/base.constants';
@Injectable()
export class CreateRefundManager extends BaseCreateManager<RefundEntity> {
async beforeProcess(): Promise<void> {
if (this.data.transaction?.status != STATUS.SETTLED) {
throw new UnprocessableEntityException({
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
message: `Failed! only transaction with status ${STATUS.SETTLED} can be refund`,
error: 'Unprocessable Entity',
});
}
return;
}
async afterProcess(): Promise<void> {
return;
}
get validateRelations(): validateRelations[] {
return [];
}
get uniqueColumns(): columnUniques[] {
return [];
}
get eventTopics(): EventTopics[] {
return [
{
topic: RefundCreatedEvent,
data: this.data,
},
];
}
get entityTarget(): any {
return RefundModel;
}
}