fix(SPG-804): cancel transaction to pending booking
continuous-integration/drone/tag Build is passing
Details
continuous-integration/drone/tag Build is passing
Details
parent
72e47c2486
commit
8dd36042eb
|
@ -132,7 +132,7 @@ export class BookingUpdateHandler
|
||||||
private couchService: CouchService,
|
private couchService: CouchService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async handle(event: TransactionChangeStatusEvent) {
|
async handle(event: TransactionUpdatedEvent) {
|
||||||
const data = event.data.data;
|
const data = event.data.data;
|
||||||
const dataID = data?.id;
|
const dataID = data?.id;
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,20 @@
|
||||||
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
|
import { EventBus, EventsHandler, IEventHandler } from '@nestjs/cqrs';
|
||||||
import { ChangeDocEvent } from 'src/modules/configuration/couch/domain/events/change-doc.event';
|
import { ChangeDocEvent } from 'src/modules/configuration/couch/domain/events/change-doc.event';
|
||||||
import { TransactionType } from '../../../constants';
|
import { TransactionType } from '../../../constants';
|
||||||
import { TransactionDataService } from '../../../data/services/transaction-data.service';
|
import { TransactionDataService } from '../../../data/services/transaction-data.service';
|
||||||
import { TaxDataService } from 'src/modules/transaction/tax/data/services/tax-data.service';
|
import { TaxDataService } from 'src/modules/transaction/tax/data/services/tax-data.service';
|
||||||
import { SalesPriceFormulaDataService } from 'src/modules/transaction/sales-price-formula/data/services/sales-price-formula-data.service';
|
import { SalesPriceFormulaDataService } from 'src/modules/transaction/sales-price-formula/data/services/sales-price-formula-data.service';
|
||||||
import { FormulaType } from 'src/modules/transaction/sales-price-formula/constants';
|
import { FormulaType } from 'src/modules/transaction/sales-price-formula/constants';
|
||||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
import {
|
||||||
|
BLANK_USER,
|
||||||
|
OPERATION,
|
||||||
|
STATUS,
|
||||||
|
} from 'src/core/strings/constants/base.constants';
|
||||||
import { TransactionModel } from '../../../data/models/transaction.model';
|
import { TransactionModel } from '../../../data/models/transaction.model';
|
||||||
import { mappingRevertTransaction } from '../managers/helpers/mapping-transaction.helper';
|
import { mappingRevertTransaction } from '../managers/helpers/mapping-transaction.helper';
|
||||||
import { apm } from '../../../../../../core/apm';
|
import { apm } from '../../../../../../core/apm';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
import { TransactionUpdatedEvent } from '../../entities/event/transaction-updated.event';
|
||||||
|
|
||||||
@EventsHandler(ChangeDocEvent)
|
@EventsHandler(ChangeDocEvent)
|
||||||
export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
|
export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
|
||||||
|
@ -16,6 +22,7 @@ export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
|
||||||
private dataService: TransactionDataService,
|
private dataService: TransactionDataService,
|
||||||
private taxService: TaxDataService,
|
private taxService: TaxDataService,
|
||||||
private formulaService: SalesPriceFormulaDataService,
|
private formulaService: SalesPriceFormulaDataService,
|
||||||
|
private eventBus: EventBus,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async handle(event: ChangeDocEvent) {
|
async handle(event: ChangeDocEvent) {
|
||||||
|
@ -25,7 +32,7 @@ export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
const database = event.data.database;
|
const database = event.data.database;
|
||||||
const data = event.data.data;
|
const data = { ...event.data.data };
|
||||||
|
|
||||||
// jika bukan database transaksi, return langsung
|
// jika bukan database transaksi, return langsung
|
||||||
if (database != 'transaction') return;
|
if (database != 'transaction') return;
|
||||||
|
@ -82,6 +89,24 @@ export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
|
||||||
apmTransactions.setLabel('Code', data?.code);
|
apmTransactions.setLabel('Code', data?.code);
|
||||||
|
|
||||||
await this.dataService.create(queryRunner, TransactionModel, data);
|
await this.dataService.create(queryRunner, TransactionModel, data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When transaction is cancel, set booking to Pending
|
||||||
|
* And tell the POS to update the "Penjualan" status to Pending
|
||||||
|
*/
|
||||||
|
if (data.status == STATUS.PENDING) {
|
||||||
|
this.eventBus.publish(
|
||||||
|
new TransactionUpdatedEvent({
|
||||||
|
id: data.id,
|
||||||
|
old: event.data.data,
|
||||||
|
data: data,
|
||||||
|
user: BLANK_USER,
|
||||||
|
description: 'Cancel Booking',
|
||||||
|
module: TABLE_NAME.TRANSACTION,
|
||||||
|
op: OPERATION.UPDATE,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
apmTransactions.result = 'Success';
|
apmTransactions.result = 'Success';
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -95,6 +95,7 @@ export function mappingRevertTransaction(data, type) {
|
||||||
editor_name: data.pos_admin?.name,
|
editor_name: data.pos_admin?.name,
|
||||||
edited_at: new Date(data.created_at),
|
edited_at: new Date(data.created_at),
|
||||||
payment_code: data.code,
|
payment_code: data.code,
|
||||||
|
status: data.status == STATUS.CANCEL ? STATUS.PENDING : data.status,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Object.assign(data, {
|
Object.assign(data, {
|
||||||
|
|
Loading…
Reference in New Issue