feat(SPG-585) DB COUCH Booking
parent
b6d067c9cd
commit
389c26e1b0
|
@ -29,15 +29,31 @@ import { ItemModel } from 'src/modules/item-related/item/data/models/item.model'
|
||||||
import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
|
import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
|
||||||
import { UserDataService } from 'src/modules/user-related/user/data/services/user-data.service';
|
import { UserDataService } from 'src/modules/user-related/user/data/services/user-data.service';
|
||||||
import { ItemDataService } from 'src/modules/item-related/item/data/services/item-data.service';
|
import { ItemDataService } from 'src/modules/item-related/item/data/services/item-data.service';
|
||||||
|
import { BookingDeletedEvent, BookingHandler } from './domain/managers/booking.handler';
|
||||||
|
import { TransactionDataService } from 'src/modules/transaction/transaction/data/services/transaction-data.service';
|
||||||
|
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
||||||
|
import { TransactionTaxModel } from 'src/modules/transaction/transaction/data/models/transaction-tax.model';
|
||||||
|
import { TransactionItemModel } from 'src/modules/transaction/transaction/data/models/transaction-item.model';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
TypeOrmModule.forFeature([ItemModel, UserModel], CONNECTION_NAME.DEFAULT),
|
TypeOrmModule.forFeature(
|
||||||
|
[
|
||||||
|
ItemModel,
|
||||||
|
UserModel,
|
||||||
|
TransactionModel,
|
||||||
|
TransactionTaxModel,
|
||||||
|
TransactionItemModel,
|
||||||
|
],
|
||||||
|
CONNECTION_NAME.DEFAULT,
|
||||||
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
],
|
],
|
||||||
controllers: [CouchDataController],
|
controllers: [CouchDataController],
|
||||||
providers: [
|
providers: [
|
||||||
|
BookingHandler,
|
||||||
|
BookingDeletedEvent,
|
||||||
PaymentMethodDeletedHandler,
|
PaymentMethodDeletedHandler,
|
||||||
PaymentMethodUpdatedHandler,
|
PaymentMethodUpdatedHandler,
|
||||||
VipCategoryDeletedHandler,
|
VipCategoryDeletedHandler,
|
||||||
|
@ -49,6 +65,7 @@ import { ItemDataService } from 'src/modules/item-related/item/data/services/ite
|
||||||
UserDeletedHandler,
|
UserDeletedHandler,
|
||||||
UserUpdatedHandler,
|
UserUpdatedHandler,
|
||||||
|
|
||||||
|
TransactionDataService,
|
||||||
UserDataService,
|
UserDataService,
|
||||||
ItemDataService,
|
ItemDataService,
|
||||||
CouchService,
|
CouchService,
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
|
||||||
|
import { TransactionDataService } from 'src/modules/transaction/transaction/data/services/transaction-data.service';
|
||||||
|
import { TransactionChangeStatusEvent } from 'src/modules/transaction/transaction/domain/entities/event/transaction-change-status.event';
|
||||||
|
import { CouchService } from '../../data/services/couch.service';
|
||||||
|
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { TransactionPaymentType } from 'src/modules/transaction/transaction/constants';
|
||||||
|
import { mappingTransaction } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/mapping-transaction.helper';
|
||||||
|
import { TransactionDeletedEvent } from 'src/modules/transaction/transaction/domain/entities/event/transaction-deleted.event';
|
||||||
|
import { TransactionUpdatedEvent } from 'src/modules/transaction/transaction/domain/entities/event/transaction-updated.event';
|
||||||
|
|
||||||
|
@EventsHandler(TransactionDeletedEvent)
|
||||||
|
export class BookingDeletedEvent
|
||||||
|
implements IEventHandler<TransactionDeletedEvent>
|
||||||
|
{
|
||||||
|
constructor(private couchService: CouchService) {}
|
||||||
|
|
||||||
|
async handle(event: TransactionDeletedEvent) {
|
||||||
|
await this.couchService.deleteDoc(
|
||||||
|
{
|
||||||
|
_id: event.data.id,
|
||||||
|
...event.data.data,
|
||||||
|
},
|
||||||
|
'item',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventsHandler(TransactionChangeStatusEvent, TransactionUpdatedEvent)
|
||||||
|
export class BookingHandler
|
||||||
|
implements IEventHandler<TransactionChangeStatusEvent>
|
||||||
|
{
|
||||||
|
constructor(
|
||||||
|
private bookingService: TransactionDataService,
|
||||||
|
private couchService: CouchService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async handle(event: TransactionChangeStatusEvent) {
|
||||||
|
const old_data = event.data.old;
|
||||||
|
const data = event.data.data;
|
||||||
|
|
||||||
|
if (data.payment_type != TransactionPaymentType.COUNTER) return;
|
||||||
|
|
||||||
|
const booking = await this.bookingService.getOneByOptions({
|
||||||
|
where: {
|
||||||
|
id: data.id,
|
||||||
|
},
|
||||||
|
relations: ['items'],
|
||||||
|
});
|
||||||
|
|
||||||
|
mappingTransaction(booking);
|
||||||
|
|
||||||
|
if (
|
||||||
|
old_data?.status != data.status &&
|
||||||
|
[STATUS.PENDING, STATUS.ACTIVE].includes(data.status)
|
||||||
|
) {
|
||||||
|
await this.couchService.createDoc(
|
||||||
|
{
|
||||||
|
_id: booking.id,
|
||||||
|
...booking,
|
||||||
|
},
|
||||||
|
'booking',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await this.couchService.updateDoc(
|
||||||
|
{
|
||||||
|
_id: booking.id,
|
||||||
|
...booking,
|
||||||
|
},
|
||||||
|
'booking',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
|
||||||
import { BaseDetailManager } from 'src/core/modules/domain/usecase/managers/base-detail.manager';
|
import { BaseDetailManager } from 'src/core/modules/domain/usecase/managers/base-detail.manager';
|
||||||
import { TransactionEntity } from '../../entities/transaction.entity';
|
import { TransactionEntity } from '../../entities/transaction.entity';
|
||||||
import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity';
|
import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity';
|
||||||
|
import { mappingTransaction } from './helpers/mapping-transaction.helper';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DetailTransactionManager extends BaseDetailManager<TransactionEntity> {
|
export class DetailTransactionManager extends BaseDetailManager<TransactionEntity> {
|
||||||
|
@ -14,69 +15,7 @@ export class DetailTransactionManager extends BaseDetailManager<TransactionEntit
|
||||||
}
|
}
|
||||||
|
|
||||||
async afterProcess(): Promise<void> {
|
async afterProcess(): Promise<void> {
|
||||||
let payment_type_bank;
|
mappingTransaction(this.result);
|
||||||
|
|
||||||
const season_period = {
|
|
||||||
id: this.result.season_period_id,
|
|
||||||
holiday_name: this.result.season_period_name,
|
|
||||||
season_type: {
|
|
||||||
id: this.result.season_period_type_id,
|
|
||||||
name: this.result.season_period_type_name,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
if (this.result.payment_type_method_id) {
|
|
||||||
payment_type_bank = {
|
|
||||||
id: this.result.payment_type_method_id,
|
|
||||||
issuer_name: this.result.payment_type_method_name,
|
|
||||||
account_number: this.result.payment_type_method_number,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const items = this.result?.['items']?.map((itemData) => {
|
|
||||||
let tenant;
|
|
||||||
|
|
||||||
if (itemData.item_tenant_id) {
|
|
||||||
tenant = {
|
|
||||||
id: itemData.item_tenant_id,
|
|
||||||
name: itemData.item_tenant_name,
|
|
||||||
share_margin: itemData.item_tenant_share_margin,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
item: {
|
|
||||||
id: itemData.item_id,
|
|
||||||
name: itemData.item_name,
|
|
||||||
item_type: itemData.item_type,
|
|
||||||
base_price: itemData.item_price,
|
|
||||||
hpp: itemData.item_hpp,
|
|
||||||
tenant: tenant,
|
|
||||||
item_category: {
|
|
||||||
id: itemData.item_category_id,
|
|
||||||
name: itemData.item_category_name,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
qty: itemData.qty,
|
|
||||||
total_price: itemData.total_price,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
Object.assign(this.result, {
|
|
||||||
season_period: season_period,
|
|
||||||
items: items,
|
|
||||||
payment_type_bank: payment_type_bank,
|
|
||||||
});
|
|
||||||
|
|
||||||
delete this.result.season_period_id;
|
|
||||||
delete this.result.season_period_name;
|
|
||||||
delete this.result.season_period_type_id;
|
|
||||||
delete this.result.season_period_type_name;
|
|
||||||
|
|
||||||
delete this.result.payment_type_method_id;
|
|
||||||
delete this.result.payment_type_method_name;
|
|
||||||
delete this.result.payment_type_method_number;
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
export function mappingTransaction(data) {
|
||||||
|
let payment_type_bank;
|
||||||
|
const season_period = {
|
||||||
|
id: data.season_period_id,
|
||||||
|
holiday_name: data.season_period_name,
|
||||||
|
season_type: {
|
||||||
|
id: data.season_period_type_id,
|
||||||
|
name: data.season_period_type_name,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (data.payment_type_method_id) {
|
||||||
|
payment_type_bank = {
|
||||||
|
id: data.payment_type_method_id,
|
||||||
|
issuer_name: data.payment_type_method_name,
|
||||||
|
account_number: data.payment_type_method_number,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const items = data?.['items']?.map((itemData) => {
|
||||||
|
let tenant;
|
||||||
|
|
||||||
|
if (itemData.item_tenant_id) {
|
||||||
|
tenant = {
|
||||||
|
id: itemData.item_tenant_id,
|
||||||
|
name: itemData.item_tenant_name,
|
||||||
|
share_margin: itemData.item_tenant_share_margin,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
item: {
|
||||||
|
id: itemData.item_id,
|
||||||
|
name: itemData.item_name,
|
||||||
|
item_type: itemData.item_type,
|
||||||
|
base_price: itemData.item_price,
|
||||||
|
hpp: itemData.item_hpp,
|
||||||
|
tenant: tenant,
|
||||||
|
item_category: {
|
||||||
|
id: itemData.item_category_id,
|
||||||
|
name: itemData.item_category_name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
qty: itemData.qty,
|
||||||
|
total_price: itemData.total_price,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.assign(data, {
|
||||||
|
season_period: season_period,
|
||||||
|
items: items,
|
||||||
|
payment_type_bank: payment_type_bank,
|
||||||
|
});
|
||||||
|
|
||||||
|
delete data.season_period_id;
|
||||||
|
delete data.season_period_name;
|
||||||
|
delete data.season_period_type_id;
|
||||||
|
delete data.season_period_type_name;
|
||||||
|
|
||||||
|
delete data.payment_type_method_id;
|
||||||
|
delete data.payment_type_method_name;
|
||||||
|
delete data.payment_type_method_number;
|
||||||
|
}
|
Loading…
Reference in New Issue