feat: add filter data scheduling date

pull/179/head
Firman Ramdhani 2025-07-11 14:03:17 +07:00
parent 5d94c7a07c
commit 6cd6bc2268
5 changed files with 50 additions and 2 deletions

View File

@ -12,6 +12,7 @@ import { DataSchedulingReadOrchestrator } from './domain/usecases/data-schedulin
import { import {
DataSchedulingDataController, DataSchedulingDataController,
DataSchedulingDefaultController, DataSchedulingDefaultController,
DataSchedulingDataLogController,
DataSchedulingSetupController, DataSchedulingSetupController,
} from './infrastructure/data-scheduling-data.controller'; } from './infrastructure/data-scheduling-data.controller';
import { DataSchedulingDataOrchestrator } from './domain/usecases/data-scheduling-data.orchestrator'; import { DataSchedulingDataOrchestrator } from './domain/usecases/data-scheduling-data.orchestrator';
@ -66,6 +67,7 @@ import { IndexDataSchedulingLogManager } from './domain/usecases/managers/index-
DataSchedulingDefaultController, DataSchedulingDefaultController,
DataSchedulingSetupController, DataSchedulingSetupController,
DataSchedulingLogReadController, DataSchedulingLogReadController,
DataSchedulingDataLogController,
], ],
providers: [ providers: [
SetupSchedulingGuard, SetupSchedulingGuard,
@ -86,6 +88,7 @@ import { IndexDataSchedulingLogManager } from './domain/usecases/managers/index-
DataSchedulingLogReadService, DataSchedulingLogReadService,
DataSchedulingDataService, DataSchedulingDataService,
DataSchedulingReadService, DataSchedulingReadService,
DataSchedulingLogDataService,
DataSchedulingDataOrchestrator, DataSchedulingDataOrchestrator,
DataSchedulingReadOrchestrator, DataSchedulingReadOrchestrator,

View File

@ -3,6 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants'; import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { DataSchedulingLogModel } from '../models/data-scheduling-log.model'; import { DataSchedulingLogModel } from '../models/data-scheduling-log.model';
import { Repository } from 'typeorm'; import { Repository } from 'typeorm';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
@Injectable() @Injectable()
export class DataSchedulingLogDataService { export class DataSchedulingLogDataService {
@ -14,4 +15,19 @@ export class DataSchedulingLogDataService {
async create(entity: any): Promise<any> { async create(entity: any): Promise<any> {
return await this.repo.save(entity); return await this.repo.save(entity);
} }
async deleteRange(from: number, to: number): Promise<any> {
try {
const deleteResult = await this.repo
.createQueryBuilder()
.delete()
.from(TABLE_NAME.DATA_SCHEDULING_LOG)
.where('log_created_at BETWEEN :from AND :to', { from, to })
.execute();
return deleteResult;
} catch (error) {
throw new Error('Failed to delete range due to an internal error.');
}
}
} }

View File

@ -119,8 +119,8 @@ export class DataSchedulingUpdatedHandler
const editorName = newData.editor_name || 'System'; const editorName = newData.editor_name || 'System';
const itemName = oldData?.name || 'an item'; const itemName = oldData?.name || 'an item';
const totalPercentageOld = decryptionTotal(oldData?.indexing_key); const totalPercentageOld = oldData?.indexing_key;
const totalPercentageNew = decryptionTotal(newData?.indexing_key); const totalPercentageNew = newData?.indexing_key;
const isTotalSame = totalPercentageOld === totalPercentageNew; const isTotalSame = totalPercentageOld === totalPercentageNew;
const labelName = `${ const labelName = `${
isTotalSame isTotalSame

View File

@ -14,6 +14,7 @@ import {
CreateDataSchedulingDto, CreateDataSchedulingDto,
EditDataSchedulingDto, EditDataSchedulingDto,
EditDataSchedulingDefaultDto, EditDataSchedulingDefaultDto,
DeleteDataSchedulingLogDto,
} from './dto/data-scheduling.dto'; } from './dto/data-scheduling.dto';
import { MODULE_NAME } from 'src/core/strings/constants/module.constants'; import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
@ -26,6 +27,7 @@ import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto'
import { ExcludePrivilege, Public } from 'src/core/guards'; import { ExcludePrivilege, Public } from 'src/core/guards';
import { SetupSchedulingGuard } from './guards/setup-scheduling.guard'; import { SetupSchedulingGuard } from './guards/setup-scheduling.guard';
import { DataSchedulingManager } from '../domain/usecases/managers/data-scheduling-default.manager'; import { DataSchedulingManager } from '../domain/usecases/managers/data-scheduling-default.manager';
import { DataSchedulingLogDataService } from '../data/services/data-scheduling-log-data.service';
@ApiTags(`${MODULE_NAME.DATA_SCHEDULING.split('-').join(' ')} - data`) @ApiTags(`${MODULE_NAME.DATA_SCHEDULING.split('-').join(' ')} - data`)
@Controller(`v1/${MODULE_NAME.DATA_SCHEDULING}`) @Controller(`v1/${MODULE_NAME.DATA_SCHEDULING}`)
@ -127,3 +129,20 @@ export class DataSchedulingSetupController {
return this.manager.setupActiveScheduling(); return this.manager.setupActiveScheduling();
} }
} }
@ApiTags(`${MODULE_NAME.DATA_SCHEDULING_LOG.split('-').join(' ')} log - Data`)
@Controller(`v1/${MODULE_NAME.DATA_SCHEDULING_LOG}`)
@Public(true)
@ApiBearerAuth('JWT')
export class DataSchedulingDataLogController {
constructor(private service: DataSchedulingLogDataService) {}
@Post('delete-range')
@ExcludePrivilege()
@UseGuards(SetupSchedulingGuard)
async setup(
@Body() data: DeleteDataSchedulingLogDto,
): Promise<{ message: string }> {
return this.service.deleteRange(data.log_created_from, data.log_created_to);
}
}

View File

@ -86,3 +86,13 @@ export class SetupDataSchedulingDto {
// @ApiProperty({ type: 'string', required: true, example: '2025-01-01' }) // @ApiProperty({ type: 'string', required: true, example: '2025-01-01' })
// date: Date; // date: Date;
} }
export class DeleteDataSchedulingLogDto {
@ApiProperty({ type: Number, required: true })
@ValidateIf((body) => body.log_created_from)
log_created_from: number;
@ApiProperty({ type: Number, required: true })
@ValidateIf((body) => body.log_created_to)
log_created_to: number;
}