feat: add read index scheduling log

pull/175/head
Firman Ramdhani 2025-07-10 19:30:38 +07:00
parent 4120e7fc1a
commit 7dadd3f8f1
11 changed files with 173 additions and 15 deletions

View File

@ -34,6 +34,7 @@ export enum MODULE_NAME {
OTP_VERIFIER = 'otp-verifier',
DATA_SCHEDULING = 'data-scheduling',
DATA_SCHEDULING_LOG = 'data-scheduling-log',
DATA_SCHEDULING_DEFAULT = 'data-scheduling-default',
DATA_SCHEDULING_ACTIVE = 'data-scheduling-active',
DATA_SCHEDULING_SETUP = 'data-scheduling-setup',

View File

@ -4,7 +4,10 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { DataSchedulingDataService } from './data/services/data-scheduling-data.service';
import { DataSchedulingReadService } from './data/services/data-scheduling-read.service';
import { DataSchedulingReadController } from './infrastructure/data-scheduling-read.controller';
import {
DataSchedulingLogReadController,
DataSchedulingReadController,
} from './infrastructure/data-scheduling-read.controller';
import { DataSchedulingReadOrchestrator } from './domain/usecases/data-scheduling-read.orchestrator';
import {
DataSchedulingDataController,
@ -39,8 +42,10 @@ 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 { DataSchedulingLogDataService } from './data/services/data-scheduling-log-data.service';
import { DataSchedulingLogModel } from './data/models/data-scheduling-log.model';
import { DataSchedulingLogReadService } from './data/services/data-scheduling-log-read.service';
import { IndexDataSchedulingLogManager } from './domain/usecases/managers/index-data-scheduling-log.manager';
@Module({
imports: [
@ -60,6 +65,7 @@ import { DataSchedulingLogModel } from './data/models/data-scheduling-log.model'
DataSchedulingReadController,
DataSchedulingDefaultController,
DataSchedulingSetupController,
DataSchedulingLogReadController,
],
providers: [
SetupSchedulingGuard,
@ -76,7 +82,8 @@ import { DataSchedulingLogModel } from './data/models/data-scheduling-log.model'
BatchConfirmDataSchedulingManager,
BatchInactiveDataSchedulingManager,
DataSchedulingLogService,
DataSchedulingLogDataService,
DataSchedulingLogReadService,
DataSchedulingDataService,
DataSchedulingReadService,
@ -84,6 +91,7 @@ import { DataSchedulingLogModel } from './data/models/data-scheduling-log.model'
DataSchedulingReadOrchestrator,
DataSchedulingManager,
IndexDataSchedulingLogManager,
DataSchedulingChangeStatusHandler,
DataSchedulingCreatedHandler,

View File

@ -5,7 +5,7 @@ import { DataSchedulingLogModel } from '../models/data-scheduling-log.model';
import { Repository } from 'typeorm';
@Injectable()
export class DataSchedulingLogService {
export class DataSchedulingLogDataService {
constructor(
@InjectRepository(DataSchedulingLogModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<DataSchedulingLogModel>,

View File

@ -0,0 +1,17 @@
import { Injectable } from '@nestjs/common';
import { DataSchedulingLogEntity } from '../../domain/entities/data-scheduling.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { Repository } from 'typeorm';
import { DataSchedulingLogModel } from '../models/data-scheduling-log.model';
@Injectable()
export class DataSchedulingLogReadService extends BaseReadService<DataSchedulingLogEntity> {
constructor(
@InjectRepository(DataSchedulingLogModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<DataSchedulingLogModel>,
) {
super(repo);
}
}

View File

@ -1,18 +1,25 @@
import { Injectable } from '@nestjs/common';
import { IndexDataSchedulingManager } from './managers/index-data-scheduling.manager';
import { DataSchedulingReadService } from '../../data/services/data-scheduling-read.service';
import { DataSchedulingEntity } from '../entities/data-scheduling.entity';
import {
DataSchedulingEntity,
DataSchedulingLogEntity,
} from '../entities/data-scheduling.entity';
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-read.orchestrator';
import { DetailDataSchedulingManager } from './managers/detail-data-scheduling.manager';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { IndexDataSchedulingLogManager } from './managers/index-data-scheduling-log.manager';
import { DataSchedulingLogReadService } from '../../data/services/data-scheduling-log-read.service';
@Injectable()
export class DataSchedulingReadOrchestrator extends BaseReadOrchestrator<DataSchedulingEntity> {
constructor(
private indexManager: IndexDataSchedulingManager,
private indexLogManager: IndexDataSchedulingLogManager,
private detailManager: DetailDataSchedulingManager,
private serviceData: DataSchedulingReadService,
private logServiceData: DataSchedulingLogReadService,
) {
super();
}
@ -24,6 +31,16 @@ export class DataSchedulingReadOrchestrator extends BaseReadOrchestrator<DataSch
return this.indexManager.getResult();
}
async indexLog(params): Promise<PaginationResponse<DataSchedulingLogEntity>> {
this.indexLogManager.setFilterParam(params);
this.indexLogManager.setService(
this.logServiceData,
TABLE_NAME.DATA_SCHEDULING_LOG,
);
await this.indexLogManager.execute();
return this.indexLogManager.getResult();
}
async detail(dataId: string): Promise<DataSchedulingEntity> {
this.detailManager.setData(dataId);
this.detailManager.setService(this.serviceData, TABLE_NAME.DATA_SCHEDULING);

View File

@ -7,7 +7,7 @@ import {
SCHEDULING_LOG_TYPE_ENUM,
} from '../../entities/data-scheduling.entity';
import { Logger } from '@nestjs/common';
import { DataSchedulingLogService } from '../../../data/services/data-scheduling-log.service';
import { DataSchedulingLogDataService } from '../../../data/services/data-scheduling-log-data.service';
@EventsHandler(DataSchedulingChangeStatusEvent)
export class DataSchedulingChangeStatusHandler
@ -15,7 +15,7 @@ export class DataSchedulingChangeStatusHandler
{
private readonly logger = new Logger(DataSchedulingChangeStatusHandler.name);
constructor(private service: DataSchedulingLogService) {}
constructor(private service: DataSchedulingLogDataService) {}
async handle(event: DataSchedulingChangeStatusEvent) {
const oldData = event?.data?.old;

View File

@ -7,7 +7,7 @@ import {
} from '../../entities/data-scheduling.entity';
import { decryptionTotal } from '../../../infrastructure/helpers';
import { Logger } from '@nestjs/common';
import { DataSchedulingLogService } from '../../../data/services/data-scheduling-log.service';
import { DataSchedulingLogDataService } from '../../../data/services/data-scheduling-log-data.service';
@EventsHandler(DataSchedulingCreatedEvent)
export class DataSchedulingCreatedHandler
@ -15,7 +15,7 @@ export class DataSchedulingCreatedHandler
{
private readonly logger = new Logger(DataSchedulingCreatedHandler.name);
constructor(private service: DataSchedulingLogService) {}
constructor(private service: DataSchedulingLogDataService) {}
async handle(event: DataSchedulingCreatedEvent) {
const data = event?.data?.data;

View File

@ -6,7 +6,7 @@ import {
SCHEDULING_LOG_TYPE_ENUM,
} from '../../entities/data-scheduling.entity';
import { Logger } from '@nestjs/common';
import { DataSchedulingLogService } from '../../../data/services/data-scheduling-log.service';
import { DataSchedulingLogDataService } from '../../../data/services/data-scheduling-log-data.service';
@EventsHandler(DataSchedulingDeletedEvent)
export class DataSchedulingDeletedHandler
@ -14,7 +14,7 @@ export class DataSchedulingDeletedHandler
{
private readonly logger = new Logger(DataSchedulingDeletedHandler.name);
constructor(private service: DataSchedulingLogService) {}
constructor(private service: DataSchedulingLogDataService) {}
async handle(event: DataSchedulingDeletedEvent) {
const deletedData = event?.data?.data;

View File

@ -10,7 +10,7 @@ import {
encryptionTotal,
} from '../../../infrastructure/helpers';
import { Logger } from '@nestjs/common';
import { DataSchedulingLogService } from '../../../data/services/data-scheduling-log.service';
import { DataSchedulingLogDataService } from '../../../data/services/data-scheduling-log-data.service';
@EventsHandler(DataSchedulingUpdatedEvent)
export class DataSchedulingUpdatedHandler
@ -18,7 +18,7 @@ export class DataSchedulingUpdatedHandler
{
private readonly logger = new Logger(DataSchedulingUpdatedHandler.name);
constructor(private service: DataSchedulingLogService) {}
constructor(private service: DataSchedulingLogDataService) {}
// Map for readable labels
private readonly labelMap: { [key: string]: string } = {

View File

@ -0,0 +1,95 @@
import { Injectable } from '@nestjs/common';
import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager';
import { DataSchedulingLogEntity } from '../../entities/data-scheduling.entity';
import { SelectQueryBuilder } from 'typeorm';
import {
Param,
RelationParam,
} from 'src/core/modules/domain/entities/base-filter.entity';
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
import { decryptionTotal } from '../../../infrastructure/helpers';
@Injectable()
export class IndexDataSchedulingLogManager extends BaseIndexManager<DataSchedulingLogEntity> {
async prepareData(): Promise<void> {
return;
}
async beforeProcess(): Promise<void> {
return;
}
async afterProcess(): Promise<void> {
return;
}
get relations(): RelationParam {
return {
joinRelations: [],
selectRelations: [],
countRelations: [],
};
}
get selects(): string[] {
return [
`${this.tableName}.id`,
`${this.tableName}.type`,
`${this.tableName}.action`,
`${this.tableName}.log_created_at`,
`${this.tableName}.data_id`,
`${this.tableName}.default_value`,
`${this.tableName}.description`,
`${this.tableName}.status`,
`${this.tableName}.name`,
`${this.tableName}.indexing_key`,
`${this.tableName}.schedule_date_from`,
`${this.tableName}.schedule_date_to`,
`${this.tableName}.created_at`,
`${this.tableName}.creator_name`,
`${this.tableName}.updated_at`,
`${this.tableName}.editor_name`,
];
}
get specificFilter(): Param[] {
return [
{
cols: `${this.tableName}.name`,
data: this.filterParam.names,
},
];
}
setQueryFilter(
queryBuilder: SelectQueryBuilder<DataSchedulingLogEntity>,
): SelectQueryBuilder<DataSchedulingLogEntity> {
if (this.filterParam.schedule_date_from) {
const dateFrom = this.filterParam.schedule_date_from;
queryBuilder.andWhere('schedule_date_from >= :dateFrom', {
dateFrom: dateFrom,
});
}
if (this.filterParam.schedule_date_to) {
const dateTo = this.filterParam.schedule_date_to;
queryBuilder.andWhere('schedule_date_from <= :dateTo', {
dateTo: dateTo,
});
}
return queryBuilder;
}
getResult(): PaginationResponse<DataSchedulingLogEntity> {
const data = this.result.data;
return {
...this.result,
data: data.map((item) => {
const total = decryptionTotal(item.indexing_key as string);
return { ...item, indexing_key: total };
}),
};
}
}

View File

@ -2,11 +2,14 @@ import { Controller, Get, Param, Query } from '@nestjs/common';
import { FilterDataSchedulingDto } from './dto/filter-data-scheduling.dto';
import { Pagination } from 'src/core/response';
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
import { DataSchedulingEntity } from '../domain/entities/data-scheduling.entity';
import {
DataSchedulingEntity,
DataSchedulingLogEntity,
} from '../domain/entities/data-scheduling.entity';
import { DataSchedulingReadOrchestrator } from '../domain/usecases/data-scheduling-read.orchestrator';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { Public } from 'src/core/guards';
import { ExcludePrivilege, Public } from 'src/core/guards';
@ApiTags(`${MODULE_NAME.DATA_SCHEDULING.split('-').join(' ')} - read`)
@Controller(`v1/${MODULE_NAME.DATA_SCHEDULING}`)
@ -28,3 +31,20 @@ export class DataSchedulingReadController {
return await this.orchestrator.detail(id);
}
}
@ApiTags(`${MODULE_NAME.DATA_SCHEDULING_LOG.split('-').join(' ')} - read`)
@Controller(`v1/${MODULE_NAME.DATA_SCHEDULING_LOG}`)
@Public(false)
@ApiBearerAuth('JWT')
export class DataSchedulingLogReadController {
constructor(private orchestrator: DataSchedulingReadOrchestrator) {}
@Get()
@Pagination()
@ExcludePrivilege()
async index(
@Query() params: FilterDataSchedulingDto,
): Promise<PaginationResponse<DataSchedulingLogEntity>> {
return await this.orchestrator.indexLog(params);
}
}