feat(SPG-800): add validation delete on data booking transaction
parent
583b754315
commit
9802d983bb
|
@ -7,7 +7,12 @@ import {
|
||||||
import { TransactionModel } from '../../../data/models/transaction.model';
|
import { TransactionModel } from '../../../data/models/transaction.model';
|
||||||
import { TransactionDeletedEvent } from '../../entities/event/transaction-deleted.event';
|
import { TransactionDeletedEvent } from '../../entities/event/transaction-deleted.event';
|
||||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
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()
|
@Injectable()
|
||||||
export class BatchDeleteTransactionManager extends BaseBatchDeleteManager<TransactionEntity> {
|
export class BatchDeleteTransactionManager extends BaseBatchDeleteManager<TransactionEntity> {
|
||||||
|
@ -16,6 +21,21 @@ export class BatchDeleteTransactionManager extends BaseBatchDeleteManager<Transa
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateData(data: TransactionEntity): Promise<void> {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 { BaseDeleteManager } from 'src/core/modules/domain/usecase/managers/base-delete.manager';
|
||||||
import { TransactionEntity } from '../../entities/transaction.entity';
|
import { TransactionEntity } from '../../entities/transaction.entity';
|
||||||
import {
|
import {
|
||||||
|
@ -7,6 +11,7 @@ import {
|
||||||
} from 'src/core/strings/constants/interface.constants';
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
import { TransactionModel } from '../../../data/models/transaction.model';
|
import { TransactionModel } from '../../../data/models/transaction.model';
|
||||||
import { TransactionDeletedEvent } from '../../entities/event/transaction-deleted.event';
|
import { TransactionDeletedEvent } from '../../entities/event/transaction-deleted.event';
|
||||||
|
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DeleteTransactionManager extends BaseDeleteManager<TransactionEntity> {
|
export class DeleteTransactionManager extends BaseDeleteManager<TransactionEntity> {
|
||||||
|
@ -15,6 +20,21 @@ export class DeleteTransactionManager extends BaseDeleteManager<TransactionEntit
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateProcess(): Promise<void> {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue