Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into fix/type-data
commit
34909a30b0
|
@ -75,11 +75,21 @@ export abstract class BaseCreateManager<Entity> extends BaseManager {
|
|||
|
||||
if (!this.eventTopics.length) return;
|
||||
for (const topic of this.eventTopics) {
|
||||
let data;
|
||||
if (!topic.data) {
|
||||
data = await this.dataService.getOneByOptions({
|
||||
where: {
|
||||
id: this.result['id'],
|
||||
},
|
||||
relations: topic.relations,
|
||||
});
|
||||
}
|
||||
|
||||
this.eventBus.publishAll([
|
||||
new topic.topic({
|
||||
id: this.result['id'],
|
||||
id: data?.['id'] ?? topic?.data?.['id'],
|
||||
old: null,
|
||||
data: topic.data,
|
||||
data: data ?? topic.data,
|
||||
user: this.user,
|
||||
description: '',
|
||||
module: this.tableName,
|
||||
|
|
|
@ -1 +1 @@
|
|||
export const DatabaseListen = ['transaction'];
|
||||
export const DatabaseListen = ['transaction', 'vip_code'];
|
||||
|
|
|
@ -37,6 +37,7 @@ import { TransactionDataService } from 'src/modules/transaction/transaction/data
|
|||
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';
|
||||
import { VipCodeCreatedHandler } from './domain/managers/vip-code.handler';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -59,6 +60,7 @@ import { TransactionItemModel } from 'src/modules/transaction/transaction/data/m
|
|||
BookingDeletedEvent,
|
||||
PaymentMethodDeletedHandler,
|
||||
PaymentMethodUpdatedHandler,
|
||||
VipCodeCreatedHandler,
|
||||
VipCategoryDeletedHandler,
|
||||
VipCategoryUpdatedHandler,
|
||||
SeasonPeriodDeletedHandler,
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
|
||||
import { CouchService } from '../../data/services/couch.service';
|
||||
import { VipCodeCreatedEvent } from 'src/modules/transaction/vip-code/domain/entities/event/vip-code-created.event';
|
||||
|
||||
@EventsHandler(VipCodeCreatedEvent)
|
||||
export class VipCodeCreatedHandler
|
||||
implements IEventHandler<VipCodeCreatedEvent>
|
||||
{
|
||||
constructor(private couchService: CouchService) {}
|
||||
|
||||
async handle(event: VipCodeCreatedEvent) {
|
||||
const data = event.data.data;
|
||||
|
||||
await this.couchService.createDoc(
|
||||
{
|
||||
_id: data.id,
|
||||
...data,
|
||||
},
|
||||
'vip_code',
|
||||
);
|
||||
}
|
||||
}
|
|
@ -45,6 +45,7 @@ export class IndexReconciliationManager extends BaseIndexManager<TransactionEnti
|
|||
`${this.tableName}.reconciliation_confirm_by`,
|
||||
|
||||
`${this.tableName}.customer_name`,
|
||||
`${this.tableName}.creator_counter_no`,
|
||||
|
||||
`${this.tableName}.payment_type`,
|
||||
`${this.tableName}.payment_type_method_id`,
|
||||
|
|
|
@ -99,6 +99,10 @@ export function mappingRevertTransaction(data, type) {
|
|||
season_period_name: data.season_period?.holiday_name ?? null,
|
||||
season_period_type_id: data.season_period?.season_type?.id ?? null,
|
||||
season_period_type_name: data.season_period?.season_type?.name ?? null,
|
||||
payment_type_method_id: data.payment_type_method?.id,
|
||||
payment_type_method_number: data.payment_type_method?.account_number,
|
||||
payment_type_method_name: data.payment_type_method?.issuer_name,
|
||||
payment_type_method_qr: data.payment_type_method?.qr_image,
|
||||
});
|
||||
|
||||
data.items?.map((item) => {
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
|
||||
import { ChangeDocEvent } from 'src/modules/configuration/couch/domain/events/change-doc.event';
|
||||
import { VipCodeDataService } from '../../../data/services/vip-code-data.service';
|
||||
import { VipCodeModel } from '../../../data/models/vip-code.model';
|
||||
import { CouchService } from 'src/modules/configuration/couch/data/services/couch.service';
|
||||
|
||||
@EventsHandler(ChangeDocEvent)
|
||||
export class CreateVipCodeHandler implements IEventHandler<ChangeDocEvent> {
|
||||
constructor(
|
||||
private dataService: VipCodeDataService,
|
||||
private couchService: CouchService,
|
||||
) {}
|
||||
|
||||
async handle(event: ChangeDocEvent) {
|
||||
const database = event.data.database;
|
||||
const data = event.data.data;
|
||||
|
||||
if (database != 'vip_code') return;
|
||||
|
||||
const queryRunner = this.dataService
|
||||
.getRepository()
|
||||
.manager.connection.createQueryRunner();
|
||||
|
||||
// jika delete
|
||||
if (data._deleted ?? false) {
|
||||
} else {
|
||||
const dataMapped = {
|
||||
...data,
|
||||
id: data._id ?? data.id,
|
||||
vip_category_id: data.vip_category?._id ?? data.vip_category?.id,
|
||||
};
|
||||
|
||||
try {
|
||||
await this.dataService.create(queryRunner, VipCodeModel, dataMapped);
|
||||
} catch (error) {
|
||||
await this.couchService.createDoc(data, 'error_vip_code');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,7 +35,7 @@ export class CreateVipCodeManager extends BaseCreateManager<VipCodeEntity> {
|
|||
return [
|
||||
{
|
||||
topic: VipCodeCreatedEvent,
|
||||
data: this.data,
|
||||
relations: ['vip_category'],
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ import { CqrsModule } from '@nestjs/cqrs';
|
|||
import { IndexVipCodeManager } from './domain/usecases/managers/index-vip-code.manager';
|
||||
import { VipCodeModel } from './data/models/vip-code.model';
|
||||
import { GenerateVipCodeManager } from './domain/usecases/managers/geneate-vip-code.manager';
|
||||
import { CreateVipCodeHandler } from './domain/usecases/handlers/create-vip-code.handler';
|
||||
import { CouchService } from 'src/modules/configuration/couch/data/services/couch.service';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -22,10 +24,13 @@ import { GenerateVipCodeManager } from './domain/usecases/managers/geneate-vip-c
|
|||
],
|
||||
controllers: [VipCodeDataController, VipCodeReadController],
|
||||
providers: [
|
||||
CreateVipCodeHandler,
|
||||
|
||||
IndexVipCodeManager,
|
||||
CreateVipCodeManager,
|
||||
GenerateVipCodeManager,
|
||||
|
||||
CouchService,
|
||||
VipCodeDataService,
|
||||
VipCodeReadService,
|
||||
|
||||
|
|
Loading…
Reference in New Issue