Merge pull request 'feat/data-trx-schedule' (#175) from feat/data-trx-schedule into development
Reviewed-on: #175pull/176/head 1.7.2-alpha.2
commit
0ddcd71245
|
@ -34,6 +34,7 @@ export enum MODULE_NAME {
|
||||||
|
|
||||||
OTP_VERIFIER = 'otp-verifier',
|
OTP_VERIFIER = 'otp-verifier',
|
||||||
DATA_SCHEDULING = 'data-scheduling',
|
DATA_SCHEDULING = 'data-scheduling',
|
||||||
|
DATA_SCHEDULING_LOG = 'data-scheduling-log',
|
||||||
DATA_SCHEDULING_DEFAULT = 'data-scheduling-default',
|
DATA_SCHEDULING_DEFAULT = 'data-scheduling-default',
|
||||||
DATA_SCHEDULING_ACTIVE = 'data-scheduling-active',
|
DATA_SCHEDULING_ACTIVE = 'data-scheduling-active',
|
||||||
DATA_SCHEDULING_SETUP = 'data-scheduling-setup',
|
DATA_SCHEDULING_SETUP = 'data-scheduling-setup',
|
||||||
|
|
|
@ -4,7 +4,10 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
import { DataSchedulingDataService } from './data/services/data-scheduling-data.service';
|
import { DataSchedulingDataService } from './data/services/data-scheduling-data.service';
|
||||||
import { DataSchedulingReadService } from './data/services/data-scheduling-read.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 { DataSchedulingReadOrchestrator } from './domain/usecases/data-scheduling-read.orchestrator';
|
||||||
import {
|
import {
|
||||||
DataSchedulingDataController,
|
DataSchedulingDataController,
|
||||||
|
@ -39,8 +42,10 @@ import { JwtModule } from '@nestjs/jwt';
|
||||||
import { JWT_EXPIRED } from 'src/core/sessions/constants';
|
import { JWT_EXPIRED } from 'src/core/sessions/constants';
|
||||||
import { JWT_SECRET } 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 { 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({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -60,6 +65,7 @@ import { DataSchedulingLogModel } from './data/models/data-scheduling-log.model'
|
||||||
DataSchedulingReadController,
|
DataSchedulingReadController,
|
||||||
DataSchedulingDefaultController,
|
DataSchedulingDefaultController,
|
||||||
DataSchedulingSetupController,
|
DataSchedulingSetupController,
|
||||||
|
DataSchedulingLogReadController,
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
SetupSchedulingGuard,
|
SetupSchedulingGuard,
|
||||||
|
@ -76,7 +82,8 @@ import { DataSchedulingLogModel } from './data/models/data-scheduling-log.model'
|
||||||
BatchConfirmDataSchedulingManager,
|
BatchConfirmDataSchedulingManager,
|
||||||
BatchInactiveDataSchedulingManager,
|
BatchInactiveDataSchedulingManager,
|
||||||
|
|
||||||
DataSchedulingLogService,
|
DataSchedulingLogDataService,
|
||||||
|
DataSchedulingLogReadService,
|
||||||
DataSchedulingDataService,
|
DataSchedulingDataService,
|
||||||
DataSchedulingReadService,
|
DataSchedulingReadService,
|
||||||
|
|
||||||
|
@ -84,6 +91,7 @@ import { DataSchedulingLogModel } from './data/models/data-scheduling-log.model'
|
||||||
DataSchedulingReadOrchestrator,
|
DataSchedulingReadOrchestrator,
|
||||||
|
|
||||||
DataSchedulingManager,
|
DataSchedulingManager,
|
||||||
|
IndexDataSchedulingLogManager,
|
||||||
|
|
||||||
DataSchedulingChangeStatusHandler,
|
DataSchedulingChangeStatusHandler,
|
||||||
DataSchedulingCreatedHandler,
|
DataSchedulingCreatedHandler,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { DataSchedulingLogModel } from '../models/data-scheduling-log.model';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DataSchedulingLogService {
|
export class DataSchedulingLogDataService {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(DataSchedulingLogModel, CONNECTION_NAME.DEFAULT)
|
@InjectRepository(DataSchedulingLogModel, CONNECTION_NAME.DEFAULT)
|
||||||
private repo: Repository<DataSchedulingLogModel>,
|
private repo: Repository<DataSchedulingLogModel>,
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,18 +1,25 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { IndexDataSchedulingManager } from './managers/index-data-scheduling.manager';
|
import { IndexDataSchedulingManager } from './managers/index-data-scheduling.manager';
|
||||||
import { DataSchedulingReadService } from '../../data/services/data-scheduling-read.service';
|
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 { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||||
import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-read.orchestrator';
|
import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-read.orchestrator';
|
||||||
import { DetailDataSchedulingManager } from './managers/detail-data-scheduling.manager';
|
import { DetailDataSchedulingManager } from './managers/detail-data-scheduling.manager';
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
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()
|
@Injectable()
|
||||||
export class DataSchedulingReadOrchestrator extends BaseReadOrchestrator<DataSchedulingEntity> {
|
export class DataSchedulingReadOrchestrator extends BaseReadOrchestrator<DataSchedulingEntity> {
|
||||||
constructor(
|
constructor(
|
||||||
private indexManager: IndexDataSchedulingManager,
|
private indexManager: IndexDataSchedulingManager,
|
||||||
|
private indexLogManager: IndexDataSchedulingLogManager,
|
||||||
private detailManager: DetailDataSchedulingManager,
|
private detailManager: DetailDataSchedulingManager,
|
||||||
private serviceData: DataSchedulingReadService,
|
private serviceData: DataSchedulingReadService,
|
||||||
|
private logServiceData: DataSchedulingLogReadService,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
@ -24,6 +31,16 @@ export class DataSchedulingReadOrchestrator extends BaseReadOrchestrator<DataSch
|
||||||
return this.indexManager.getResult();
|
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> {
|
async detail(dataId: string): Promise<DataSchedulingEntity> {
|
||||||
this.detailManager.setData(dataId);
|
this.detailManager.setData(dataId);
|
||||||
this.detailManager.setService(this.serviceData, TABLE_NAME.DATA_SCHEDULING);
|
this.detailManager.setService(this.serviceData, TABLE_NAME.DATA_SCHEDULING);
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
SCHEDULING_LOG_TYPE_ENUM,
|
SCHEDULING_LOG_TYPE_ENUM,
|
||||||
} from '../../entities/data-scheduling.entity';
|
} from '../../entities/data-scheduling.entity';
|
||||||
import { Logger } from '@nestjs/common';
|
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)
|
@EventsHandler(DataSchedulingChangeStatusEvent)
|
||||||
export class DataSchedulingChangeStatusHandler
|
export class DataSchedulingChangeStatusHandler
|
||||||
|
@ -15,43 +15,46 @@ export class DataSchedulingChangeStatusHandler
|
||||||
{
|
{
|
||||||
private readonly logger = new Logger(DataSchedulingChangeStatusHandler.name);
|
private readonly logger = new Logger(DataSchedulingChangeStatusHandler.name);
|
||||||
|
|
||||||
constructor(private service: DataSchedulingLogService) {}
|
constructor(private service: DataSchedulingLogDataService) {}
|
||||||
|
|
||||||
async handle(event: DataSchedulingChangeStatusEvent) {
|
async handle(event: DataSchedulingChangeStatusEvent) {
|
||||||
const oldData = event?.data?.old;
|
// Prevent execution if the event data is null, which can happen if triggered from the default percentage update service.
|
||||||
const newData = event?.data?.data;
|
if (event.data?.data) {
|
||||||
|
const oldData = event?.data?.old;
|
||||||
|
const newData = event?.data?.data;
|
||||||
|
|
||||||
const oldStatus = capitalizeEachWord(oldData?.status);
|
const oldStatus = capitalizeEachWord(oldData?.status);
|
||||||
const newStatus = capitalizeEachWord(newData.status);
|
const newStatus = capitalizeEachWord(newData?.status);
|
||||||
|
|
||||||
const scheduleName = newData?.name || 'an item';
|
const scheduleName = newData?.name || 'an item';
|
||||||
const editorName = newData.editor_name || 'System';
|
const editorName = newData.editor_name || 'System';
|
||||||
const description = `<p><b>${editorName}</b> changed the status of <b>${scheduleName}</b> from <b><i>${oldStatus}</i></b> to <b><i>${newStatus}</i></b>.</p>`;
|
const description = `<p><b>${editorName}</b> changed the status of <b>${scheduleName}</b> from <b><i>${oldStatus}</i></b> to <b><i>${newStatus}</i></b>.</p>`;
|
||||||
|
|
||||||
const payload: DataSchedulingLogEntity = {
|
const payload: DataSchedulingLogEntity = {
|
||||||
type: SCHEDULING_LOG_TYPE_ENUM.DATA_SCHEDULING,
|
type: SCHEDULING_LOG_TYPE_ENUM.DATA_SCHEDULING,
|
||||||
action: SCHEDULING_LOG_ACTION_ENUM.CHANGE_STATUS,
|
action: SCHEDULING_LOG_ACTION_ENUM.CHANGE_STATUS,
|
||||||
log_created_at: new Date().getTime(),
|
log_created_at: new Date().getTime(),
|
||||||
|
|
||||||
data_id: newData?.id,
|
data_id: newData?.id,
|
||||||
name: newData?.name,
|
name: newData?.name,
|
||||||
indexing_key: newData?.indexing_key,
|
indexing_key: newData?.indexing_key,
|
||||||
schedule_date_from: newData?.schedule_date_from,
|
schedule_date_from: newData?.schedule_date_from,
|
||||||
schedule_date_to: newData?.schedule_date_to,
|
schedule_date_to: newData?.schedule_date_to,
|
||||||
|
|
||||||
status: newData?.status,
|
status: newData?.status,
|
||||||
creator_id: newData?.creator_id,
|
creator_id: newData?.creator_id,
|
||||||
creator_name: newData?.creator_name,
|
creator_name: newData?.creator_name,
|
||||||
editor_id: newData?.editor_id,
|
editor_id: newData?.editor_id,
|
||||||
editor_name: newData?.editor_name,
|
editor_name: newData?.editor_name,
|
||||||
created_at: newData?.created_at,
|
created_at: newData?.created_at,
|
||||||
updated_at: newData?.updated_at,
|
updated_at: newData?.updated_at,
|
||||||
description: description,
|
description: description,
|
||||||
};
|
};
|
||||||
|
|
||||||
await this.service.create(payload as any);
|
await this.service.create(payload as any);
|
||||||
this.logger.verbose(
|
this.logger.verbose(
|
||||||
`[SCHEDULING LOG] Change status data for ID: ${payload.data_id}`,
|
`[SCHEDULING LOG] Change status data for ID: ${payload.data_id}`,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
} from '../../entities/data-scheduling.entity';
|
} from '../../entities/data-scheduling.entity';
|
||||||
import { decryptionTotal } from '../../../infrastructure/helpers';
|
import { decryptionTotal } from '../../../infrastructure/helpers';
|
||||||
import { Logger } from '@nestjs/common';
|
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)
|
@EventsHandler(DataSchedulingCreatedEvent)
|
||||||
export class DataSchedulingCreatedHandler
|
export class DataSchedulingCreatedHandler
|
||||||
|
@ -15,7 +15,7 @@ export class DataSchedulingCreatedHandler
|
||||||
{
|
{
|
||||||
private readonly logger = new Logger(DataSchedulingCreatedHandler.name);
|
private readonly logger = new Logger(DataSchedulingCreatedHandler.name);
|
||||||
|
|
||||||
constructor(private service: DataSchedulingLogService) {}
|
constructor(private service: DataSchedulingLogDataService) {}
|
||||||
|
|
||||||
async handle(event: DataSchedulingCreatedEvent) {
|
async handle(event: DataSchedulingCreatedEvent) {
|
||||||
const data = event?.data?.data;
|
const data = event?.data?.data;
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
SCHEDULING_LOG_TYPE_ENUM,
|
SCHEDULING_LOG_TYPE_ENUM,
|
||||||
} from '../../entities/data-scheduling.entity';
|
} from '../../entities/data-scheduling.entity';
|
||||||
import { Logger } from '@nestjs/common';
|
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)
|
@EventsHandler(DataSchedulingDeletedEvent)
|
||||||
export class DataSchedulingDeletedHandler
|
export class DataSchedulingDeletedHandler
|
||||||
|
@ -14,7 +14,7 @@ export class DataSchedulingDeletedHandler
|
||||||
{
|
{
|
||||||
private readonly logger = new Logger(DataSchedulingDeletedHandler.name);
|
private readonly logger = new Logger(DataSchedulingDeletedHandler.name);
|
||||||
|
|
||||||
constructor(private service: DataSchedulingLogService) {}
|
constructor(private service: DataSchedulingLogDataService) {}
|
||||||
|
|
||||||
async handle(event: DataSchedulingDeletedEvent) {
|
async handle(event: DataSchedulingDeletedEvent) {
|
||||||
const deletedData = event?.data?.data;
|
const deletedData = event?.data?.data;
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {
|
||||||
encryptionTotal,
|
encryptionTotal,
|
||||||
} from '../../../infrastructure/helpers';
|
} from '../../../infrastructure/helpers';
|
||||||
import { Logger } from '@nestjs/common';
|
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)
|
@EventsHandler(DataSchedulingUpdatedEvent)
|
||||||
export class DataSchedulingUpdatedHandler
|
export class DataSchedulingUpdatedHandler
|
||||||
|
@ -18,7 +18,7 @@ export class DataSchedulingUpdatedHandler
|
||||||
{
|
{
|
||||||
private readonly logger = new Logger(DataSchedulingUpdatedHandler.name);
|
private readonly logger = new Logger(DataSchedulingUpdatedHandler.name);
|
||||||
|
|
||||||
constructor(private service: DataSchedulingLogService) {}
|
constructor(private service: DataSchedulingLogDataService) {}
|
||||||
|
|
||||||
// Map for readable labels
|
// Map for readable labels
|
||||||
private readonly labelMap: { [key: string]: string } = {
|
private readonly labelMap: { [key: string]: string } = {
|
||||||
|
|
|
@ -2,7 +2,12 @@ import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { UserProvider, UsersSession } from 'src/core/sessions';
|
import { UserProvider, UsersSession } from 'src/core/sessions';
|
||||||
import { BLANK_USER } from 'src/core/strings/constants/base.constants';
|
import { BLANK_USER } from 'src/core/strings/constants/base.constants';
|
||||||
import { EditDataSchedulingDefaultDto } from '../../../infrastructure/dto/data-scheduling.dto';
|
import { EditDataSchedulingDefaultDto } from '../../../infrastructure/dto/data-scheduling.dto';
|
||||||
import { DataSchedulingDefaultEntity } from '../../entities/data-scheduling.entity';
|
import {
|
||||||
|
DataSchedulingDefaultEntity,
|
||||||
|
DataSchedulingLogEntity,
|
||||||
|
SCHEDULING_LOG_ACTION_ENUM,
|
||||||
|
SCHEDULING_LOG_TYPE_ENUM,
|
||||||
|
} from '../../entities/data-scheduling.entity';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { DataSchedulingDefaultModel } from '../../../data/models/data-scheduling-default.model';
|
import { DataSchedulingDefaultModel } from '../../../data/models/data-scheduling-default.model';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
@ -10,6 +15,7 @@ import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import { SelectQueryBuilder } from 'typeorm';
|
import { SelectQueryBuilder } from 'typeorm';
|
||||||
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';
|
||||||
|
import { DataSchedulingLogModel } from '../../../data/models/data-scheduling-log.model';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DataSchedulingManager {
|
export class DataSchedulingManager {
|
||||||
|
@ -21,6 +27,9 @@ export class DataSchedulingManager {
|
||||||
|
|
||||||
@InjectRepository(DataSchedulingDefaultModel)
|
@InjectRepository(DataSchedulingDefaultModel)
|
||||||
private repository: Repository<DataSchedulingDefaultModel>,
|
private repository: Repository<DataSchedulingDefaultModel>,
|
||||||
|
|
||||||
|
@InjectRepository(DataSchedulingLogModel)
|
||||||
|
private repositoryLog: Repository<DataSchedulingLogModel>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
private getUser(): UsersSession {
|
private getUser(): UsersSession {
|
||||||
|
@ -60,7 +69,35 @@ export class DataSchedulingManager {
|
||||||
created_at: dateNow,
|
created_at: dateNow,
|
||||||
updated_at: dateNow,
|
updated_at: dateNow,
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveData = await this.repository.save(payload);
|
const saveData = await this.repository.save(payload);
|
||||||
|
|
||||||
|
if (existData?.default_value !== saveData?.default_value) {
|
||||||
|
const description = existData?.id
|
||||||
|
? `<p><b>${saveData.editor_name}</b> mengubah pengaturan <b><i>Default Percentage</i></b> dari <b><i>${existData.default_value}%</i></b> menjadi <b><i>${saveData.default_value}%</i></b>.</p>`
|
||||||
|
: `<p><b>${saveData.creator_name}</b> membuat pengaturan <b><i>Default Percentage</i></b> dengan value <b><i>${saveData.default_value}%</i></b>.</p>`;
|
||||||
|
|
||||||
|
const logPayload: DataSchedulingLogEntity = {
|
||||||
|
type: SCHEDULING_LOG_TYPE_ENUM.DEFAULT_PERCENTAGE,
|
||||||
|
action: existData?.id
|
||||||
|
? SCHEDULING_LOG_ACTION_ENUM.UPDATE
|
||||||
|
: SCHEDULING_LOG_ACTION_ENUM.CREATE,
|
||||||
|
log_created_at: new Date().getTime(),
|
||||||
|
status: undefined,
|
||||||
|
|
||||||
|
data_id: saveData?.id,
|
||||||
|
creator_id: saveData?.creator_id,
|
||||||
|
creator_name: saveData?.creator_name,
|
||||||
|
editor_id: saveData?.editor_id,
|
||||||
|
editor_name: saveData?.editor_name,
|
||||||
|
created_at: saveData?.created_at,
|
||||||
|
updated_at: saveData?.updated_at,
|
||||||
|
default_value: saveData?.default_value,
|
||||||
|
description: description,
|
||||||
|
};
|
||||||
|
|
||||||
|
await this.repositoryLog.save(logPayload as any);
|
||||||
|
}
|
||||||
await this.publishEventUpdates();
|
await this.publishEventUpdates();
|
||||||
return saveData;
|
return saveData;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 };
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,11 +2,14 @@ import { Controller, Get, Param, Query } from '@nestjs/common';
|
||||||
import { FilterDataSchedulingDto } from './dto/filter-data-scheduling.dto';
|
import { FilterDataSchedulingDto } from './dto/filter-data-scheduling.dto';
|
||||||
import { Pagination } from 'src/core/response';
|
import { Pagination } from 'src/core/response';
|
||||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
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 { DataSchedulingReadOrchestrator } from '../domain/usecases/data-scheduling-read.orchestrator';
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
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`)
|
@ApiTags(`${MODULE_NAME.DATA_SCHEDULING.split('-').join(' ')} - read`)
|
||||||
@Controller(`v1/${MODULE_NAME.DATA_SCHEDULING}`)
|
@Controller(`v1/${MODULE_NAME.DATA_SCHEDULING}`)
|
||||||
|
@ -28,3 +31,20 @@ export class DataSchedulingReadController {
|
||||||
return await this.orchestrator.detail(id);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue