feat(SPG-1124): add feature get scheduling active
parent
65419461cb
commit
41e70c0655
|
@ -35,4 +35,6 @@ export enum MODULE_NAME {
|
||||||
OTP_VERIFIER = 'otp-verifier',
|
OTP_VERIFIER = 'otp-verifier',
|
||||||
DATA_SCHEDULING = 'data-scheduling',
|
DATA_SCHEDULING = 'data-scheduling',
|
||||||
DATA_SCHEDULING_DEFAULT = 'data-scheduling-default',
|
DATA_SCHEDULING_DEFAULT = 'data-scheduling-default',
|
||||||
|
DATA_SCHEDULING_ACTIVE = 'data-scheduling-active',
|
||||||
|
DATA_SCHEDULING_SETUP = 'data-scheduling-setup',
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { DataSchedulingReadService } from './data/services/data-scheduling-read.
|
||||||
import { DataSchedulingReadController } from './infrastructure/data-scheduling-read.controller';
|
import { 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 {
|
||||||
|
DataSchedulingActiveController,
|
||||||
DataSchedulingDataController,
|
DataSchedulingDataController,
|
||||||
DataSchedulingDefaultController,
|
DataSchedulingDefaultController,
|
||||||
DataSchedulingSetupController,
|
DataSchedulingSetupController,
|
||||||
|
@ -27,7 +28,7 @@ import { BatchConfirmDataSchedulingManager } from './domain/usecases/managers/ba
|
||||||
import { BatchInactiveDataSchedulingManager } from './domain/usecases/managers/batch-inactive-data-scheduling.manager';
|
import { BatchInactiveDataSchedulingManager } from './domain/usecases/managers/batch-inactive-data-scheduling.manager';
|
||||||
import { DataSchedulingModel } from './data/models/data-scheduling.model';
|
import { DataSchedulingModel } from './data/models/data-scheduling.model';
|
||||||
import { DataSchedulingDefaultModel } from './data/models/data-scheduling-default.model';
|
import { DataSchedulingDefaultModel } from './data/models/data-scheduling-default.model';
|
||||||
import { DataSchedulingDefaultManager } from './domain/usecases/managers/data-scheduling-default.manager';
|
import { DataSchedulingManager } from './domain/usecases/managers/data-scheduling-default.manager';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -42,6 +43,7 @@ import { DataSchedulingDefaultManager } from './domain/usecases/managers/data-sc
|
||||||
DataSchedulingDataController,
|
DataSchedulingDataController,
|
||||||
DataSchedulingReadController,
|
DataSchedulingReadController,
|
||||||
DataSchedulingDefaultController,
|
DataSchedulingDefaultController,
|
||||||
|
DataSchedulingActiveController,
|
||||||
DataSchedulingSetupController,
|
DataSchedulingSetupController,
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
|
@ -64,7 +66,7 @@ import { DataSchedulingDefaultManager } from './domain/usecases/managers/data-sc
|
||||||
DataSchedulingDataOrchestrator,
|
DataSchedulingDataOrchestrator,
|
||||||
DataSchedulingReadOrchestrator,
|
DataSchedulingReadOrchestrator,
|
||||||
|
|
||||||
DataSchedulingDefaultManager,
|
DataSchedulingManager,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class DataSchedulingModule {}
|
export class DataSchedulingModule {}
|
||||||
|
|
|
@ -11,3 +11,7 @@ export interface DataSchedulingEntity extends BaseStatusEntity {
|
||||||
export interface DataSchedulingDefaultEntity extends BaseEntity {
|
export interface DataSchedulingDefaultEntity extends BaseEntity {
|
||||||
default_value: number;
|
default_value: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DataSchedulingActiveEntity {
|
||||||
|
value: number;
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { BaseCreateManager } from 'src/core/modules/domain/usecase/managers/base
|
||||||
import { DataSchedulingCreatedEvent } from '../../entities/event/data-scheduling-created.event';
|
import { DataSchedulingCreatedEvent } from '../../entities/event/data-scheduling-created.event';
|
||||||
import { encryptionTotal } from '../../../infrastructure/helpers';
|
import { encryptionTotal } from '../../../infrastructure/helpers';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
|
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CreateDataSchedulingManager extends BaseCreateManager<DataSchedulingEntity> {
|
export class CreateDataSchedulingManager extends BaseCreateManager<DataSchedulingEntity> {
|
||||||
|
@ -36,6 +37,7 @@ export class CreateDataSchedulingManager extends BaseCreateManager<DataSchedulin
|
||||||
if (this.data) {
|
if (this.data) {
|
||||||
Object.assign(this.data, {
|
Object.assign(this.data, {
|
||||||
indexing_key: encryptionTotal(total),
|
indexing_key: encryptionTotal(total),
|
||||||
|
status: STATUS.ACTIVE,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,21 +2,29 @@ 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,
|
||||||
|
DataSchedulingEntity,
|
||||||
|
} 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';
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import { SelectQueryBuilder } from 'typeorm';
|
import { SelectQueryBuilder } from 'typeorm';
|
||||||
|
import { DataSchedulingModel } from '../../../data/models/data-scheduling.model';
|
||||||
|
import { decryptionTotal } from '../../../infrastructure/helpers';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DataSchedulingDefaultManager {
|
export class DataSchedulingManager {
|
||||||
@Inject()
|
@Inject()
|
||||||
protected userProvider: UserProvider;
|
protected userProvider: UserProvider;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(DataSchedulingDefaultModel)
|
@InjectRepository(DataSchedulingDefaultModel)
|
||||||
private repository: Repository<DataSchedulingDefaultModel>,
|
private repository: Repository<DataSchedulingDefaultModel>,
|
||||||
|
|
||||||
|
@InjectRepository(DataSchedulingModel)
|
||||||
|
private repoSchedule: Repository<DataSchedulingModel>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
private getUser(): UsersSession {
|
private getUser(): UsersSession {
|
||||||
|
@ -63,4 +71,21 @@ export class DataSchedulingDefaultManager {
|
||||||
async getData() {
|
async getData() {
|
||||||
return this.queryBuilder().getOne();
|
return this.queryBuilder().getOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getActiveData(date) {
|
||||||
|
const qb = this.repoSchedule.createQueryBuilder(TABLE_NAME.DATA_SCHEDULING);
|
||||||
|
|
||||||
|
const findData: DataSchedulingEntity = await qb
|
||||||
|
.where('status = :status', { status: 'active' })
|
||||||
|
.andWhere('schedule_date_from <= :date', { date: date })
|
||||||
|
.andWhere('schedule_date_to >= :date', { date: date })
|
||||||
|
.getOne();
|
||||||
|
|
||||||
|
if (!findData) {
|
||||||
|
const defaultData = await this.queryBuilder().getOne();
|
||||||
|
return { value: defaultData?.default_value };
|
||||||
|
}
|
||||||
|
|
||||||
|
return { value: decryptionTotal(findData.indexing_key as string) };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
Patch,
|
Patch,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
|
Query,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { DataSchedulingDataOrchestrator } from '../domain/usecases/data-scheduling-data.orchestrator';
|
import { DataSchedulingDataOrchestrator } from '../domain/usecases/data-scheduling-data.orchestrator';
|
||||||
|
@ -19,6 +20,7 @@ import {
|
||||||
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';
|
||||||
import {
|
import {
|
||||||
|
DataSchedulingActiveEntity,
|
||||||
DataSchedulingDefaultEntity,
|
DataSchedulingDefaultEntity,
|
||||||
DataSchedulingEntity,
|
DataSchedulingEntity,
|
||||||
} from '../domain/entities/data-scheduling.entity';
|
} from '../domain/entities/data-scheduling.entity';
|
||||||
|
@ -26,7 +28,8 @@ import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
|
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 { DataSchedulingDefaultManager } from '../domain/usecases/managers/data-scheduling-default.manager';
|
import { DataSchedulingManager } from '../domain/usecases/managers/data-scheduling-default.manager';
|
||||||
|
import { FilterActiveDataSchedulingDto } from './dto/filter-data-scheduling.dto';
|
||||||
|
|
||||||
@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}`)
|
||||||
|
@ -92,13 +95,13 @@ export class DataSchedulingDataController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiTags(
|
@ApiTags(
|
||||||
`${MODULE_NAME.DATA_SCHEDULING_DEFAULT.split('-').join(' ')} setup - Data`,
|
`${MODULE_NAME.DATA_SCHEDULING_DEFAULT.split('-').join(' ')} default - Data`,
|
||||||
)
|
)
|
||||||
@Controller(`v1/${MODULE_NAME.DATA_SCHEDULING_DEFAULT}`)
|
@Controller(`v1/${MODULE_NAME.DATA_SCHEDULING_DEFAULT}`)
|
||||||
@Public(false)
|
@Public(false)
|
||||||
@ApiBearerAuth('JWT')
|
@ApiBearerAuth('JWT')
|
||||||
export class DataSchedulingDefaultController {
|
export class DataSchedulingDefaultController {
|
||||||
constructor(private manager: DataSchedulingDefaultManager) {}
|
constructor(private manager: DataSchedulingManager) {}
|
||||||
@Post()
|
@Post()
|
||||||
async create(
|
async create(
|
||||||
@Body() data: EditDataSchedulingDefaultDto,
|
@Body() data: EditDataSchedulingDefaultDto,
|
||||||
|
@ -112,11 +115,30 @@ export class DataSchedulingDefaultController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiTags(`${MODULE_NAME.DATA_SCHEDULING.split('-').join(' ')} setup - Data`)
|
@ApiTags(
|
||||||
@Controller(``)
|
`${MODULE_NAME.DATA_SCHEDULING_ACTIVE.split('-').join(' ')} active - Data`,
|
||||||
|
)
|
||||||
|
@Controller(`v1/${MODULE_NAME.DATA_SCHEDULING_ACTIVE}`)
|
||||||
|
@Public(false)
|
||||||
|
@ApiBearerAuth('JWT')
|
||||||
|
export class DataSchedulingActiveController {
|
||||||
|
constructor(private manager: DataSchedulingManager) {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
async get(
|
||||||
|
@Query() params: FilterActiveDataSchedulingDto,
|
||||||
|
): Promise<DataSchedulingActiveEntity> {
|
||||||
|
return await this.manager.getActiveData(params?.date);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiTags(
|
||||||
|
`${MODULE_NAME.DATA_SCHEDULING_SETUP.split('-').join(' ')} setup - Data`,
|
||||||
|
)
|
||||||
|
@Controller(`v1/${MODULE_NAME.DATA_SCHEDULING_SETUP}`)
|
||||||
@Public(true)
|
@Public(true)
|
||||||
export class DataSchedulingSetupController {
|
export class DataSchedulingSetupController {
|
||||||
@Post('v1/data-scheduling-setup')
|
@Post()
|
||||||
@ExcludePrivilege()
|
@ExcludePrivilege()
|
||||||
@UseGuards(SetupSchedulingGuard)
|
@UseGuards(SetupSchedulingGuard)
|
||||||
async setup(
|
async setup(
|
||||||
|
|
|
@ -15,3 +15,9 @@ export class FilterDataSchedulingDto
|
||||||
@ValidateIf((body) => body.schedule_date_to)
|
@ValidateIf((body) => body.schedule_date_to)
|
||||||
schedule_date_to: Date;
|
schedule_date_to: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class FilterActiveDataSchedulingDto {
|
||||||
|
@ApiProperty({ type: 'string', required: true })
|
||||||
|
@ValidateIf((body) => body.schedule_date_from)
|
||||||
|
date: Date;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue