fix(SPG-641) Validasi ketika process save untuk aksi di rekonsiliasi, save data di refund, dan aksi di booking
parent
cc92ef26a1
commit
c5cec31ab5
|
@ -11,10 +11,25 @@ import {
|
|||
} 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';
|
||||
|
||||
@Injectable()
|
||||
export class BatchCancelReconciliationManager extends BaseBatchUpdateStatusManager<TransactionEntity> {
|
||||
validateData(data: TransactionEntity): Promise<void> {
|
||||
async validateData(data: TransactionEntity): Promise<void> {
|
||||
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,
|
||||
|
|
|
@ -4,6 +4,7 @@ import {
|
|||
UnprocessableEntityException,
|
||||
} from '@nestjs/common';
|
||||
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
|
||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
|
@ -18,7 +19,20 @@ export class CancelReconciliationManager extends BaseUpdateStatusManager<Transac
|
|||
}
|
||||
|
||||
async validateProcess(): Promise<void> {
|
||||
if (this.data.is_recap_transaction) {
|
||||
// untuk dapat current status
|
||||
const transaction = await this.dataService.getOneByOptions({
|
||||
where: {
|
||||
id: this.dataId,
|
||||
},
|
||||
});
|
||||
|
||||
if (transaction.status != STATUS.SETTLED) {
|
||||
throw new UnprocessableEntityException({
|
||||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
message: `Failed! cant cancel transaction not settled`,
|
||||
error: 'Unprocessable Entity',
|
||||
});
|
||||
} else if (this.data.is_recap_transaction) {
|
||||
throw new UnprocessableEntityException({
|
||||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
message: `Failed! cant cancel recap data`,
|
||||
|
|
|
@ -16,8 +16,14 @@ import { STATUS } from 'src/core/strings/constants/base.constants';
|
|||
|
||||
@Injectable()
|
||||
export class BatchConfirmRefundManager extends BaseBatchUpdateStatusManager<RefundEntity> {
|
||||
validateData(data: RefundEntity): Promise<void> {
|
||||
if (![STATUS.DRAFT, STATUS.PENDING].includes(data.status)) {
|
||||
async validateData(data: RefundEntity): Promise<void> {
|
||||
if (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',
|
||||
});
|
||||
} else if (![STATUS.DRAFT, STATUS.PENDING].includes(data.status)) {
|
||||
throw new UnprocessableEntityException({
|
||||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
message: `Failed! only data with status ${STATUS.DRAFT} and ${STATUS.PENDING} can be confirmed`,
|
||||
|
|
|
@ -38,6 +38,14 @@ export class ConfirmRefundManager extends BaseUpdateStatusManager<RefundEntity>
|
|||
relations: ['transaction'],
|
||||
});
|
||||
|
||||
if (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',
|
||||
});
|
||||
}
|
||||
|
||||
if (data.status == STATUS.DRAFT) {
|
||||
Object.assign(this.data, {
|
||||
code: `RF-${data.transaction?.invoice_code?.split('-')[1]}`,
|
||||
|
|
|
@ -30,7 +30,14 @@ export class CreateRefundManager extends BaseCreateManager<RefundEntity> {
|
|||
refund_items: refund_items,
|
||||
});
|
||||
|
||||
if (this.data.transaction?.status != STATUS.SETTLED) {
|
||||
const transaction = await this.dataServiceFirstOpt.getOneByOptions({
|
||||
where: {
|
||||
id: this.data.transaction.id,
|
||||
status: STATUS.SETTLED,
|
||||
},
|
||||
});
|
||||
|
||||
if (!transaction) {
|
||||
throw new UnprocessableEntityException({
|
||||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
message: `Failed! only transaction with status ${STATUS.SETTLED} can be refund`,
|
||||
|
|
|
@ -17,7 +17,14 @@ import { STATUS } from 'src/core/strings/constants/base.constants';
|
|||
@Injectable()
|
||||
export class UpdateRefundManager extends BaseUpdateManager<RefundEntity> {
|
||||
async validateProcess(): Promise<void> {
|
||||
if (this.data.transaction?.status != STATUS.SETTLED) {
|
||||
const transaction = await this.dataServiceFirstOpt.getOneByOptions({
|
||||
where: {
|
||||
id: this.data.transaction.id,
|
||||
status: STATUS.SETTLED,
|
||||
},
|
||||
});
|
||||
|
||||
if (!transaction) {
|
||||
throw new UnprocessableEntityException({
|
||||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
message: `Failed! only transaction with status ${STATUS.SETTLED} can be refund`,
|
||||
|
|
|
@ -12,6 +12,7 @@ import { BatchDeleteRefundManager } from './managers/batch-delete-refund.manager
|
|||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { CancelRefundManager } from './managers/cancel-refund.manager';
|
||||
import { BatchCancelRefundManager } from './managers/batch-cancel-refund.manager';
|
||||
import { TransactionDataService } from 'src/modules/transaction/transaction/data/services/transaction-data.service';
|
||||
|
||||
@Injectable()
|
||||
export class RefundDataOrchestrator {
|
||||
|
@ -25,18 +26,27 @@ export class RefundDataOrchestrator {
|
|||
private batchCancelManager: BatchCancelRefundManager,
|
||||
private batchConfirmManager: BatchConfirmRefundManager,
|
||||
private serviceData: RefundDataService,
|
||||
private transactionDataService: TransactionDataService,
|
||||
) {}
|
||||
|
||||
async create(data): Promise<RefundEntity> {
|
||||
this.createManager.setData(data);
|
||||
this.createManager.setService(this.serviceData, TABLE_NAME.REFUND);
|
||||
this.createManager.setService(
|
||||
this.serviceData,
|
||||
TABLE_NAME.REFUND,
|
||||
this.transactionDataService,
|
||||
);
|
||||
await this.createManager.execute();
|
||||
return this.createManager.getResult();
|
||||
}
|
||||
|
||||
async update(dataId, data): Promise<RefundEntity> {
|
||||
this.updateManager.setData(dataId, data);
|
||||
this.updateManager.setService(this.serviceData, TABLE_NAME.REFUND);
|
||||
this.updateManager.setService(
|
||||
this.serviceData,
|
||||
TABLE_NAME.REFUND,
|
||||
this.transactionDataService,
|
||||
);
|
||||
await this.updateManager.execute();
|
||||
return this.updateManager.getResult();
|
||||
}
|
||||
|
|
|
@ -21,12 +21,14 @@ import { RefundModel } from './data/models/refund.model';
|
|||
import { BatchCancelRefundManager } from './domain/usecases/managers/batch-cancel-refund.manager';
|
||||
import { CancelRefundManager } from './domain/usecases/managers/cancel-refund.manager';
|
||||
import { RefundItemModel } from './data/models/refund-item.model';
|
||||
import { TransactionDataService } from '../transaction/data/services/transaction-data.service';
|
||||
import { TransactionModel } from '../transaction/data/models/transaction.model';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
TypeOrmModule.forFeature(
|
||||
[RefundModel, RefundItemModel],
|
||||
[RefundModel, RefundItemModel, TransactionModel],
|
||||
CONNECTION_NAME.DEFAULT,
|
||||
),
|
||||
CqrsModule,
|
||||
|
@ -46,6 +48,7 @@ import { RefundItemModel } from './data/models/refund-item.model';
|
|||
|
||||
RefundDataService,
|
||||
RefundReadService,
|
||||
TransactionDataService,
|
||||
|
||||
RefundDataOrchestrator,
|
||||
RefundReadOrchestrator,
|
||||
|
|
|
@ -18,7 +18,7 @@ export class RefundUpdatedHandler
|
|||
|
||||
if (
|
||||
old_data.status != current_data.data ||
|
||||
event.data.op == OPERATION.DELETE
|
||||
(event.data.op == OPERATION.DELETE && current_data.status != STATUS.DRAFT)
|
||||
) {
|
||||
const queryRunner = this.dataService
|
||||
.getRepository()
|
||||
|
|
Loading…
Reference in New Issue