feat(SPG-800): add validation delete on data booking transaction

pull/56/head
Firman Ramdhani 2024-08-07 10:31:19 +07:00
parent 583b754315
commit 9802d983bb
2 changed files with 42 additions and 2 deletions

View File

@ -7,7 +7,12 @@ import {
import { TransactionModel } from '../../../data/models/transaction.model';
import { TransactionDeletedEvent } from '../../entities/event/transaction-deleted.event';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { Injectable } from '@nestjs/common';
import {
HttpStatus,
Injectable,
UnprocessableEntityException,
} from '@nestjs/common';
import { STATUS } from 'src/core/strings/constants/base.constants';
@Injectable()
export class BatchDeleteTransactionManager extends BaseBatchDeleteManager<TransactionEntity> {
@ -16,6 +21,21 @@ export class BatchDeleteTransactionManager extends BaseBatchDeleteManager<Transa
}
async validateData(data: TransactionEntity): Promise<void> {
const allowDelete = [
STATUS.DRAFT,
STATUS.ACTIVE,
STATUS.CANCEL,
STATUS.PENDING,
STATUS.EXPIRED,
].includes(data.status);
if (!allowDelete) {
throw new UnprocessableEntityException({
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
message: `Gagal! data dengan status ${data.status} tidak bisa di hapus!`,
error: 'Unprocessable Entity',
});
}
return;
}

View File

@ -1,4 +1,8 @@
import { Injectable } from '@nestjs/common';
import {
HttpStatus,
Injectable,
UnprocessableEntityException,
} from '@nestjs/common';
import { BaseDeleteManager } from 'src/core/modules/domain/usecase/managers/base-delete.manager';
import { TransactionEntity } from '../../entities/transaction.entity';
import {
@ -7,6 +11,7 @@ import {
} from 'src/core/strings/constants/interface.constants';
import { TransactionModel } from '../../../data/models/transaction.model';
import { TransactionDeletedEvent } from '../../entities/event/transaction-deleted.event';
import { STATUS } from 'src/core/strings/constants/base.constants';
@Injectable()
export class DeleteTransactionManager extends BaseDeleteManager<TransactionEntity> {
@ -15,6 +20,21 @@ export class DeleteTransactionManager extends BaseDeleteManager<TransactionEntit
}
async validateProcess(): Promise<void> {
const allowDelete = [
STATUS.DRAFT,
STATUS.ACTIVE,
STATUS.CANCEL,
STATUS.PENDING,
STATUS.EXPIRED,
].includes(this.data.status);
if (!allowDelete) {
throw new UnprocessableEntityException({
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
message: `Gagal! data dengan status ${this.data.status} tidak bisa di hapus!`,
error: 'Unprocessable Entity',
});
}
return;
}