feat: integration save scheduling data log to database
parent
cfb863b7d0
commit
4120e7fc1a
|
@ -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,
|
||||
}),
|
||||
|
|
|
@ -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,
|
||||
|
||||
|
|
|
@ -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<DataSchedulingLogModel>,
|
||||
) {}
|
||||
|
||||
async create(entity: any): Promise<any> {
|
||||
return await this.repo.save(entity);
|
||||
}
|
||||
}
|
|
@ -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<DataSchedulingLogModel>,
|
||||
) {}
|
||||
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}`,
|
||||
);
|
||||
|
|
|
@ -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<DataSchedulingLogModel>,
|
||||
) {}
|
||||
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}`,
|
||||
);
|
||||
|
|
|
@ -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<DataSchedulingLogModel>,
|
||||
) {}
|
||||
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}`,
|
||||
);
|
||||
|
|
|
@ -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<DataSchedulingLogModel>,
|
||||
) {}
|
||||
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}`,
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue