Merge pull request 'feat: integration save to couch' (#171) from feat/data-trx-schedule into development

Reviewed-on: #171
pull/172/head
firmanr 2025-07-08 11:13:15 +07:00
commit fb207c7a6c
3 changed files with 32 additions and 9 deletions

View File

@ -4,4 +4,5 @@ export const DatabaseListen = [
'pos_activity', 'pos_activity',
'pos_cash_activity', 'pos_cash_activity',
'time_groups', 'time_groups',
'api_configuration',
]; ];

View File

@ -13,6 +13,7 @@ import * as momentTz from 'moment-timezone';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants'; import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { DataSchedulingEntity } from 'src/modules/configuration/data-scheduling/domain/entities/data-scheduling.entity'; import { DataSchedulingEntity } from 'src/modules/configuration/data-scheduling/domain/entities/data-scheduling.entity';
import { decryptionTotal } from 'src/modules/configuration/data-scheduling/infrastructure/helpers'; import { decryptionTotal } from 'src/modules/configuration/data-scheduling/infrastructure/helpers';
import { Logger } from '@nestjs/common';
@EventsHandler( @EventsHandler(
DataSchedulingCreatedEvent, DataSchedulingCreatedEvent,
@ -21,6 +22,10 @@ import { decryptionTotal } from 'src/modules/configuration/data-scheduling/infra
DataSchedulingDeletedEvent, DataSchedulingDeletedEvent,
) )
export class DataSchedulingUpdatedHandler implements IEventHandler { export class DataSchedulingUpdatedHandler implements IEventHandler {
private readonly logger = new Logger(DataSchedulingUpdatedHandler.name);
private readonly permanentID = 'e6166c86-d85d-43f8-86ad-c9e85a88f68f';
private readonly couchTableName = 'api_configuration';
constructor( constructor(
private couchService: CouchService, private couchService: CouchService,
@ -33,10 +38,31 @@ export class DataSchedulingUpdatedHandler implements IEventHandler {
async handle() { async handle() {
const activeData = await this.getActiveData(); const activeData = await this.getActiveData();
console.log( const existData = await this.couchService.getDoc(
activeData, this.permanentID,
'handle when data scheduling status change and data updated', this.couchTableName,
); );
if (!existData) {
this.logger.verbose('CREATE SCHEDULING CONFIG');
await this.couchService.createDoc(
{
_id: this.permanentID,
id: this.permanentID,
...activeData,
},
this.couchTableName,
);
} else if (existData) {
this.logger.verbose('UPDATE SCHEDULING CONFIG');
await this.couchService.updateDoc(
{
_id: this.permanentID,
id: this.permanentID,
...activeData,
},
this.couchTableName,
);
}
} }
async getActiveData() { async getActiveData() {

View File

@ -8,7 +8,6 @@ import { DataSchedulingDefaultModel } from '../../../data/models/data-scheduling
import { Repository } from 'typeorm'; import { Repository } from 'typeorm';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants'; import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { SelectQueryBuilder } from 'typeorm'; import { SelectQueryBuilder } from 'typeorm';
import { DataSchedulingModel } from '../../../data/models/data-scheduling.model';
import { EventBus } from '@nestjs/cqrs'; import { EventBus } from '@nestjs/cqrs';
import { DataSchedulingChangeStatusEvent } from '../../entities/event/data-scheduling-change-status.event'; import { DataSchedulingChangeStatusEvent } from '../../entities/event/data-scheduling-change-status.event';
@ -22,9 +21,6 @@ export class DataSchedulingManager {
@InjectRepository(DataSchedulingDefaultModel) @InjectRepository(DataSchedulingDefaultModel)
private repository: Repository<DataSchedulingDefaultModel>, private repository: Repository<DataSchedulingDefaultModel>,
@InjectRepository(DataSchedulingModel)
private repoSchedule: Repository<DataSchedulingModel>,
) {} ) {}
private getUser(): UsersSession { private getUser(): UsersSession {
@ -64,9 +60,9 @@ export class DataSchedulingManager {
created_at: dateNow, created_at: dateNow,
updated_at: dateNow, updated_at: dateNow,
}; };
const saveData = await this.repository.save(payload);
await this.publishEventUpdates(); await this.publishEventUpdates();
return this.repository.save(payload); return saveData;
} }
async getData() { async getData() {