feat(SPG-1124): add feature get scheduling active
parent
65419461cb
commit
41e70c0655
|
@ -35,4 +35,6 @@ export enum MODULE_NAME {
|
|||
OTP_VERIFIER = 'otp-verifier',
|
||||
DATA_SCHEDULING = 'data-scheduling',
|
||||
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 { DataSchedulingReadOrchestrator } from './domain/usecases/data-scheduling-read.orchestrator';
|
||||
import {
|
||||
DataSchedulingActiveController,
|
||||
DataSchedulingDataController,
|
||||
DataSchedulingDefaultController,
|
||||
DataSchedulingSetupController,
|
||||
|
@ -27,7 +28,7 @@ import { BatchConfirmDataSchedulingManager } from './domain/usecases/managers/ba
|
|||
import { BatchInactiveDataSchedulingManager } from './domain/usecases/managers/batch-inactive-data-scheduling.manager';
|
||||
import { DataSchedulingModel } from './data/models/data-scheduling.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({
|
||||
imports: [
|
||||
|
@ -42,6 +43,7 @@ import { DataSchedulingDefaultManager } from './domain/usecases/managers/data-sc
|
|||
DataSchedulingDataController,
|
||||
DataSchedulingReadController,
|
||||
DataSchedulingDefaultController,
|
||||
DataSchedulingActiveController,
|
||||
DataSchedulingSetupController,
|
||||
],
|
||||
providers: [
|
||||
|
@ -64,7 +66,7 @@ import { DataSchedulingDefaultManager } from './domain/usecases/managers/data-sc
|
|||
DataSchedulingDataOrchestrator,
|
||||
DataSchedulingReadOrchestrator,
|
||||
|
||||
DataSchedulingDefaultManager,
|
||||
DataSchedulingManager,
|
||||
],
|
||||
})
|
||||
export class DataSchedulingModule {}
|
||||
|
|
|
@ -11,3 +11,7 @@ export interface DataSchedulingEntity extends BaseStatusEntity {
|
|||
export interface DataSchedulingDefaultEntity extends BaseEntity {
|
||||
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 { encryptionTotal } from '../../../infrastructure/helpers';
|
||||
import * as moment from 'moment';
|
||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||
|
||||
@Injectable()
|
||||
export class CreateDataSchedulingManager extends BaseCreateManager<DataSchedulingEntity> {
|
||||
|
@ -36,6 +37,7 @@ export class CreateDataSchedulingManager extends BaseCreateManager<DataSchedulin
|
|||
if (this.data) {
|
||||
Object.assign(this.data, {
|
||||
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 { BLANK_USER } from 'src/core/strings/constants/base.constants';
|
||||
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 { DataSchedulingDefaultModel } from '../../../data/models/data-scheduling-default.model';
|
||||
import { Repository } from 'typeorm';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { SelectQueryBuilder } from 'typeorm';
|
||||
import { DataSchedulingModel } from '../../../data/models/data-scheduling.model';
|
||||
import { decryptionTotal } from '../../../infrastructure/helpers';
|
||||
|
||||
@Injectable()
|
||||
export class DataSchedulingDefaultManager {
|
||||
export class DataSchedulingManager {
|
||||
@Inject()
|
||||
protected userProvider: UserProvider;
|
||||
|
||||
constructor(
|
||||
@InjectRepository(DataSchedulingDefaultModel)
|
||||
private repository: Repository<DataSchedulingDefaultModel>,
|
||||
|
||||
@InjectRepository(DataSchedulingModel)
|
||||
private repoSchedule: Repository<DataSchedulingModel>,
|
||||
) {}
|
||||
|
||||
private getUser(): UsersSession {
|
||||
|
@ -63,4 +71,21 @@ export class DataSchedulingDefaultManager {
|
|||
async getData() {
|
||||
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,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
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 { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import {
|
||||
DataSchedulingActiveEntity,
|
||||
DataSchedulingDefaultEntity,
|
||||
DataSchedulingEntity,
|
||||
} 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 { ExcludePrivilege, Public } from 'src/core/guards';
|
||||
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`)
|
||||
@Controller(`v1/${MODULE_NAME.DATA_SCHEDULING}`)
|
||||
|
@ -92,13 +95,13 @@ export class DataSchedulingDataController {
|
|||
}
|
||||
|
||||
@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}`)
|
||||
@Public(false)
|
||||
@ApiBearerAuth('JWT')
|
||||
export class DataSchedulingDefaultController {
|
||||
constructor(private manager: DataSchedulingDefaultManager) {}
|
||||
constructor(private manager: DataSchedulingManager) {}
|
||||
@Post()
|
||||
async create(
|
||||
@Body() data: EditDataSchedulingDefaultDto,
|
||||
|
@ -112,11 +115,30 @@ export class DataSchedulingDefaultController {
|
|||
}
|
||||
}
|
||||
|
||||
@ApiTags(`${MODULE_NAME.DATA_SCHEDULING.split('-').join(' ')} setup - Data`)
|
||||
@Controller(``)
|
||||
@ApiTags(
|
||||
`${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)
|
||||
export class DataSchedulingSetupController {
|
||||
@Post('v1/data-scheduling-setup')
|
||||
@Post()
|
||||
@ExcludePrivilege()
|
||||
@UseGuards(SetupSchedulingGuard)
|
||||
async setup(
|
||||
|
|
|
@ -15,3 +15,9 @@ export class FilterDataSchedulingDto
|
|||
@ValidateIf((body) => body.schedule_date_to)
|
||||
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