import { HttpStatus, Injectable, UnprocessableEntityException, } from '@nestjs/common'; import { BaseUpdateManager } from 'src/core/modules/domain/usecase/managers/base-update.manager'; import { RefundEntity } from '../../entities/refund.entity'; import { RefundModel } from '../../../data/models/refund.model'; import { RefundUpdatedEvent } from '../../entities/event/refund-updated.event'; import { EventTopics, columnUniques, validateRelations, } from 'src/core/strings/constants/interface.constants'; import { STATUS } from 'src/core/strings/constants/base.constants'; @Injectable() export class UpdateRefundManager extends BaseUpdateManager { async validateProcess(): Promise { 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 beforeProcess(): Promise { return; } async afterProcess(): Promise { return; } get validateRelations(): validateRelations[] { return []; } get uniqueColumns(): columnUniques[] { return []; } get entityTarget(): any { return RefundModel; } get eventTopics(): EventTopics[] { return [ { topic: RefundUpdatedEvent, data: this.data, }, ]; } }