diff --git a/src/app.module.ts b/src/app.module.ts index 631989f..0af318e 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -110,6 +110,7 @@ import { OtpCheckerGuard } from './core/guards/domain/otp-checker.guard'; import { DataSchedulingModel } from './modules/configuration/data-scheduling/data/models/data-scheduling.model'; import { DataSchedulingModule } from './modules/configuration/data-scheduling/data-scheduling.module'; import { DataSchedulingDefaultModel } from './modules/configuration/data-scheduling/data/models/data-scheduling-default.model'; +import { DataSchedulingLogModel } from './modules/configuration/data-scheduling/data/models/data-scheduling-log.model'; @Module({ imports: [ @@ -183,6 +184,7 @@ import { DataSchedulingDefaultModel } from './modules/configuration/data-schedul // Data Scheduling DataSchedulingModel, DataSchedulingDefaultModel, + DataSchedulingLogModel, ], synchronize: false, }), diff --git a/src/modules/configuration/data-scheduling/data-scheduling.module.ts b/src/modules/configuration/data-scheduling/data-scheduling.module.ts index ef409bd..a47c394 100644 --- a/src/modules/configuration/data-scheduling/data-scheduling.module.ts +++ b/src/modules/configuration/data-scheduling/data-scheduling.module.ts @@ -38,6 +38,8 @@ import { DataSchedulingUpdatedHandler } from './domain/usecases/handlers/data-sc import { JwtModule } from '@nestjs/jwt'; import { JWT_EXPIRED } from 'src/core/sessions/constants'; import { JWT_SECRET } from 'src/core/sessions/constants'; + +import { DataSchedulingLogService } from './data/services/data-scheduling-log.service'; import { DataSchedulingLogModel } from './data/models/data-scheduling-log.model'; @Module({ @@ -74,6 +76,7 @@ import { DataSchedulingLogModel } from './data/models/data-scheduling-log.model' BatchConfirmDataSchedulingManager, BatchInactiveDataSchedulingManager, + DataSchedulingLogService, DataSchedulingDataService, DataSchedulingReadService, diff --git a/src/modules/configuration/data-scheduling/data/services/data-scheduling-log.service.ts b/src/modules/configuration/data-scheduling/data/services/data-scheduling-log.service.ts new file mode 100644 index 0000000..b714c40 --- /dev/null +++ b/src/modules/configuration/data-scheduling/data/services/data-scheduling-log.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; +import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants'; +import { DataSchedulingLogModel } from '../models/data-scheduling-log.model'; +import { Repository } from 'typeorm'; + +@Injectable() +export class DataSchedulingLogService { + constructor( + @InjectRepository(DataSchedulingLogModel, CONNECTION_NAME.DEFAULT) + private repo: Repository, + ) {} + + async create(entity: any): Promise { + return await this.repo.save(entity); + } +} diff --git a/src/modules/configuration/data-scheduling/domain/usecases/handlers/data-scheduling-change-status.handler.ts b/src/modules/configuration/data-scheduling/domain/usecases/handlers/data-scheduling-change-status.handler.ts index d8074e4..b7c95dd 100644 --- a/src/modules/configuration/data-scheduling/domain/usecases/handlers/data-scheduling-change-status.handler.ts +++ b/src/modules/configuration/data-scheduling/domain/usecases/handlers/data-scheduling-change-status.handler.ts @@ -6,10 +6,8 @@ import { SCHEDULING_LOG_ACTION_ENUM, SCHEDULING_LOG_TYPE_ENUM, } from '../../entities/data-scheduling.entity'; -import { InjectRepository } from '@nestjs/typeorm'; -import { DataSchedulingLogModel } from '../../../data/models/data-scheduling-log.model'; -import { Repository } from 'typeorm'; import { Logger } from '@nestjs/common'; +import { DataSchedulingLogService } from '../../../data/services/data-scheduling-log.service'; @EventsHandler(DataSchedulingChangeStatusEvent) export class DataSchedulingChangeStatusHandler @@ -17,10 +15,7 @@ export class DataSchedulingChangeStatusHandler { private readonly logger = new Logger(DataSchedulingChangeStatusHandler.name); - constructor( - @InjectRepository(DataSchedulingLogModel) - private repository: Repository, - ) {} + constructor(private service: DataSchedulingLogService) {} async handle(event: DataSchedulingChangeStatusEvent) { const oldData = event?.data?.old; @@ -54,7 +49,7 @@ export class DataSchedulingChangeStatusHandler description: description, }; - await this.repository.save(payload as any); + await this.service.create(payload as any); this.logger.verbose( `[SCHEDULING LOG] Change status data for ID: ${payload.data_id}`, ); diff --git a/src/modules/configuration/data-scheduling/domain/usecases/handlers/data-scheduling-created.handler.ts b/src/modules/configuration/data-scheduling/domain/usecases/handlers/data-scheduling-created.handler.ts index c35b8e2..b1c6c1d 100644 --- a/src/modules/configuration/data-scheduling/domain/usecases/handlers/data-scheduling-created.handler.ts +++ b/src/modules/configuration/data-scheduling/domain/usecases/handlers/data-scheduling-created.handler.ts @@ -6,10 +6,8 @@ import { SCHEDULING_LOG_TYPE_ENUM, } from '../../entities/data-scheduling.entity'; import { decryptionTotal } from '../../../infrastructure/helpers'; -import { DataSchedulingLogModel } from '../../../data/models/data-scheduling-log.model'; -import { InjectRepository } from '@nestjs/typeorm'; -import { Repository } from 'typeorm'; import { Logger } from '@nestjs/common'; +import { DataSchedulingLogService } from '../../../data/services/data-scheduling-log.service'; @EventsHandler(DataSchedulingCreatedEvent) export class DataSchedulingCreatedHandler @@ -17,10 +15,7 @@ export class DataSchedulingCreatedHandler { private readonly logger = new Logger(DataSchedulingCreatedHandler.name); - constructor( - @InjectRepository(DataSchedulingLogModel) - private repository: Repository, - ) {} + constructor(private service: DataSchedulingLogService) {} async handle(event: DataSchedulingCreatedEvent) { const data = event?.data?.data; @@ -50,7 +45,7 @@ export class DataSchedulingCreatedHandler description: description, }; - await this.repository.save(payload as any); + await this.service.create(payload as any); this.logger.verbose( `[SCHEDULING LOG] Create data for ID: ${payload.data_id}`, ); diff --git a/src/modules/configuration/data-scheduling/domain/usecases/handlers/data-scheduling-deleted.handler.ts b/src/modules/configuration/data-scheduling/domain/usecases/handlers/data-scheduling-deleted.handler.ts index 8ba8e87..d9a13b7 100644 --- a/src/modules/configuration/data-scheduling/domain/usecases/handlers/data-scheduling-deleted.handler.ts +++ b/src/modules/configuration/data-scheduling/domain/usecases/handlers/data-scheduling-deleted.handler.ts @@ -5,10 +5,8 @@ import { SCHEDULING_LOG_ACTION_ENUM, SCHEDULING_LOG_TYPE_ENUM, } from '../../entities/data-scheduling.entity'; -import { InjectRepository } from '@nestjs/typeorm'; -import { DataSchedulingLogModel } from '../../../data/models/data-scheduling-log.model'; -import { Repository } from 'typeorm'; import { Logger } from '@nestjs/common'; +import { DataSchedulingLogService } from '../../../data/services/data-scheduling-log.service'; @EventsHandler(DataSchedulingDeletedEvent) export class DataSchedulingDeletedHandler @@ -16,10 +14,7 @@ export class DataSchedulingDeletedHandler { private readonly logger = new Logger(DataSchedulingDeletedHandler.name); - constructor( - @InjectRepository(DataSchedulingLogModel) - private repository: Repository, - ) {} + constructor(private service: DataSchedulingLogService) {} async handle(event: DataSchedulingDeletedEvent) { const deletedData = event?.data?.data; @@ -56,7 +51,7 @@ export class DataSchedulingDeletedHandler description: description, }; - await this.repository.save(payload as any); + await this.service.create(payload as any); this.logger.verbose( `[SCHEDULING LOG] Delete data for ID: ${payload.data_id}`, ); diff --git a/src/modules/configuration/data-scheduling/domain/usecases/handlers/data-scheduling-updated.handler.ts b/src/modules/configuration/data-scheduling/domain/usecases/handlers/data-scheduling-updated.handler.ts index d170e90..2d45674 100644 --- a/src/modules/configuration/data-scheduling/domain/usecases/handlers/data-scheduling-updated.handler.ts +++ b/src/modules/configuration/data-scheduling/domain/usecases/handlers/data-scheduling-updated.handler.ts @@ -9,10 +9,8 @@ import { decryptionTotal, encryptionTotal, } from '../../../infrastructure/helpers'; -import { InjectRepository } from '@nestjs/typeorm'; -import { DataSchedulingLogModel } from '../../../data/models/data-scheduling-log.model'; -import { Repository } from 'typeorm'; import { Logger } from '@nestjs/common'; +import { DataSchedulingLogService } from '../../../data/services/data-scheduling-log.service'; @EventsHandler(DataSchedulingUpdatedEvent) export class DataSchedulingUpdatedHandler @@ -20,10 +18,7 @@ export class DataSchedulingUpdatedHandler { private readonly logger = new Logger(DataSchedulingUpdatedHandler.name); - constructor( - @InjectRepository(DataSchedulingLogModel) - private repository: Repository, - ) {} + constructor(private service: DataSchedulingLogService) {} // Map for readable labels private readonly labelMap: { [key: string]: string } = { @@ -82,7 +77,7 @@ export class DataSchedulingUpdatedHandler description: description, }; - await this.repository.save(payload as any); + await this.service.create(payload as any); this.logger.verbose( `[SCHEDULING LOG] Update data for ID: ${payload.data_id}`, );