import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager'; import { EventTopics, validateRelations, } from 'src/core/strings/constants/interface.constants'; import { BatchResult } from 'src/core/response/domain/ok-response.interface'; import { HttpStatus, Injectable, UnprocessableEntityException, } from '@nestjs/common'; import { TransactionEntity } from 'src/modules/transaction/transaction/domain/entities/transaction.entity'; import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model'; import { STATUS } from 'src/core/strings/constants/base.constants'; import { TransactionChangeStatusEvent } from 'src/modules/transaction/transaction/domain/entities/event/transaction-change-status.event'; @Injectable() export class BatchCancelReconciliationManager extends BaseBatchUpdateStatusManager { async validateData(data: TransactionEntity): Promise { const transaction = await this.dataService.getOneByOptions({ where: { id: data.id, }, }); if (transaction.status != STATUS.SETTLED) { throw new UnprocessableEntityException({ statusCode: HttpStatus.UNPROCESSABLE_ENTITY, message: `Failed! cant cancel transaction not settled`, error: 'Unprocessable Entity', }); } Object.assign(data, { reconciliation_mdr: this.data.reconciliation_mdr ?? null, reconciliation_confirm_by: this.user.name, reconciliation_confirm_date: new Date().getTime(), status: this.dataStatus, reconciliation_status: this.dataStatus, payment_date: this.data.payment_date, }); if (data.is_recap_transaction) { throw new UnprocessableEntityException({ statusCode: HttpStatus.UNPROCESSABLE_ENTITY, message: `Failed! cant cancel recap data`, error: 'Unprocessable Entity', }); } return; } beforeProcess(): Promise { return; } afterProcess(): Promise { return; } get validateRelations(): validateRelations[] { return []; } get entityTarget(): any { return TransactionModel; } get eventTopics(): EventTopics[] { return [ { topic: TransactionChangeStatusEvent, }, ]; } getResult(): BatchResult { return this.result; } }