feat: integration save to couch
parent
b8f0a1a20e
commit
f79db3343d
|
@ -4,4 +4,5 @@ export const DatabaseListen = [
|
|||
'pos_activity',
|
||||
'pos_cash_activity',
|
||||
'time_groups',
|
||||
'api_configuration',
|
||||
];
|
||||
|
|
|
@ -13,6 +13,7 @@ import * as momentTz from 'moment-timezone';
|
|||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { DataSchedulingEntity } from 'src/modules/configuration/data-scheduling/domain/entities/data-scheduling.entity';
|
||||
import { decryptionTotal } from 'src/modules/configuration/data-scheduling/infrastructure/helpers';
|
||||
import { Logger } from '@nestjs/common';
|
||||
|
||||
@EventsHandler(
|
||||
DataSchedulingCreatedEvent,
|
||||
|
@ -21,6 +22,10 @@ import { decryptionTotal } from 'src/modules/configuration/data-scheduling/infra
|
|||
DataSchedulingDeletedEvent,
|
||||
)
|
||||
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(
|
||||
private couchService: CouchService,
|
||||
|
||||
|
@ -33,10 +38,31 @@ export class DataSchedulingUpdatedHandler implements IEventHandler {
|
|||
|
||||
async handle() {
|
||||
const activeData = await this.getActiveData();
|
||||
console.log(
|
||||
activeData,
|
||||
'handle when data scheduling status change and data updated',
|
||||
const existData = await this.couchService.getDoc(
|
||||
this.permanentID,
|
||||
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() {
|
||||
|
|
|
@ -8,7 +8,6 @@ import { DataSchedulingDefaultModel } from '../../../data/models/data-scheduling
|
|||
import { Repository } from 'typeorm';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { SelectQueryBuilder } from 'typeorm';
|
||||
import { DataSchedulingModel } from '../../../data/models/data-scheduling.model';
|
||||
import { EventBus } from '@nestjs/cqrs';
|
||||
import { DataSchedulingChangeStatusEvent } from '../../entities/event/data-scheduling-change-status.event';
|
||||
|
||||
|
@ -22,9 +21,6 @@ export class DataSchedulingManager {
|
|||
|
||||
@InjectRepository(DataSchedulingDefaultModel)
|
||||
private repository: Repository<DataSchedulingDefaultModel>,
|
||||
|
||||
@InjectRepository(DataSchedulingModel)
|
||||
private repoSchedule: Repository<DataSchedulingModel>,
|
||||
) {}
|
||||
|
||||
private getUser(): UsersSession {
|
||||
|
@ -64,9 +60,9 @@ export class DataSchedulingManager {
|
|||
created_at: dateNow,
|
||||
updated_at: dateNow,
|
||||
};
|
||||
|
||||
const saveData = await this.repository.save(payload);
|
||||
await this.publishEventUpdates();
|
||||
return this.repository.save(payload);
|
||||
return saveData;
|
||||
}
|
||||
|
||||
async getData() {
|
||||
|
|
Loading…
Reference in New Issue