feat(SPG-405) DB Kode Diskon VIP
parent
56e7d25acd
commit
28dcac39f0
|
@ -75,11 +75,21 @@ export abstract class BaseCreateManager<Entity> extends BaseManager {
|
||||||
|
|
||||||
if (!this.eventTopics.length) return;
|
if (!this.eventTopics.length) return;
|
||||||
for (const topic of this.eventTopics) {
|
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([
|
this.eventBus.publishAll([
|
||||||
new topic.topic({
|
new topic.topic({
|
||||||
id: this.result['id'],
|
id: data?.['id'] ?? topic?.data?.['id'],
|
||||||
old: null,
|
old: null,
|
||||||
data: topic.data,
|
data: data ?? topic.data,
|
||||||
user: this.user,
|
user: this.user,
|
||||||
description: '',
|
description: '',
|
||||||
module: this.tableName,
|
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 { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
||||||
import { TransactionTaxModel } from 'src/modules/transaction/transaction/data/models/transaction-tax.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 { TransactionItemModel } from 'src/modules/transaction/transaction/data/models/transaction-item.model';
|
||||||
|
import { VipCodeCreatedHandler } from './domain/managers/vip-code.handler';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -59,6 +60,7 @@ import { TransactionItemModel } from 'src/modules/transaction/transaction/data/m
|
||||||
BookingDeletedEvent,
|
BookingDeletedEvent,
|
||||||
PaymentMethodDeletedHandler,
|
PaymentMethodDeletedHandler,
|
||||||
PaymentMethodUpdatedHandler,
|
PaymentMethodUpdatedHandler,
|
||||||
|
VipCodeCreatedHandler,
|
||||||
VipCategoryDeletedHandler,
|
VipCategoryDeletedHandler,
|
||||||
VipCategoryUpdatedHandler,
|
VipCategoryUpdatedHandler,
|
||||||
SeasonPeriodDeletedHandler,
|
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}.reconciliation_confirm_by`,
|
||||||
|
|
||||||
`${this.tableName}.customer_name`,
|
`${this.tableName}.customer_name`,
|
||||||
|
`${this.tableName}.creator_counter_no`,
|
||||||
|
|
||||||
`${this.tableName}.payment_type`,
|
`${this.tableName}.payment_type`,
|
||||||
`${this.tableName}.payment_type_method_id`,
|
`${this.tableName}.payment_type_method_id`,
|
||||||
|
|
|
@ -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 [
|
return [
|
||||||
{
|
{
|
||||||
topic: VipCodeCreatedEvent,
|
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 { IndexVipCodeManager } from './domain/usecases/managers/index-vip-code.manager';
|
||||||
import { VipCodeModel } from './data/models/vip-code.model';
|
import { VipCodeModel } from './data/models/vip-code.model';
|
||||||
import { GenerateVipCodeManager } from './domain/usecases/managers/geneate-vip-code.manager';
|
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({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -22,10 +24,13 @@ import { GenerateVipCodeManager } from './domain/usecases/managers/geneate-vip-c
|
||||||
],
|
],
|
||||||
controllers: [VipCodeDataController, VipCodeReadController],
|
controllers: [VipCodeDataController, VipCodeReadController],
|
||||||
providers: [
|
providers: [
|
||||||
|
CreateVipCodeHandler,
|
||||||
|
|
||||||
IndexVipCodeManager,
|
IndexVipCodeManager,
|
||||||
CreateVipCodeManager,
|
CreateVipCodeManager,
|
||||||
GenerateVipCodeManager,
|
GenerateVipCodeManager,
|
||||||
|
|
||||||
|
CouchService,
|
||||||
VipCodeDataService,
|
VipCodeDataService,
|
||||||
VipCodeReadService,
|
VipCodeReadService,
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue