Merge pull request 'feat(SPG-1124): create feature crud data scheduling and data scheduling default' (#164) from feat/data-trx-schedule into development
Reviewed-on: #164pull/167/head 1.6.27-alpha.1
commit
df4ff9e23d
|
@ -47,3 +47,5 @@ SUPERSET_ADMIN_PASSWORD=admin
|
|||
|
||||
WHATSAPP_BUSINESS_ACCOUNT_NUMBER_ID=604883366037548
|
||||
WHATSAPP_BUSINESS_ACCESS_TOKEN=EAAINOvRRiEEBO9yQsYDnYtjHZB7q1nZCwbBpRcxIGMDWajKZBtmWxNRKvPYkS95KQZBsZBOvSFyjiEg5CcCZBZBtaSZApxyV8fiA3cEyVwf7iVZBQP2YCTPRQZArMFeeXbO0uq5TGygmjsIz3M4YxcUHxPzKO4pKxIyxnzcoUZCqCSo1NqQSLVf3a0JyZAwgDXGL55dV
|
||||
|
||||
SETUP_SCHEDULING_KEY=scheduling_key_example
|
|
@ -44,3 +44,5 @@ SUPERSET_ADMIN_PASSWORD=admin
|
|||
|
||||
WHATSAPP_BUSINESS_ACCOUNT_NUMBER_ID=604883366037548
|
||||
WHATSAPP_BUSINESS_ACCESS_TOKEN=EAAINOvRRiEEBO9yQsYDnYtjHZB7q1nZCwbBpRcxIGMDWajKZBtmWxNRKvPYkS95KQZBsZBOvSFyjiEg5CcCZBZBtaSZApxyV8fiA3cEyVwf7iVZBQP2YCTPRQZArMFeeXbO0uq5TGygmjsIz3M4YxcUHxPzKO4pKxIyxnzcoUZCqCSo1NqQSLVf3a0JyZAwgDXGL55dV
|
||||
|
||||
SETUP_SCHEDULING_KEY=scheduling_key_example
|
|
@ -107,6 +107,9 @@ import { OtpVerificationModel } from './modules/configuration/otp-verification/d
|
|||
import { OtpVerifierModel } from './modules/configuration/otp-verification/data/models/otp-verifier.model';
|
||||
import { RescheduleVerificationModel } from './modules/booking-online/order/data/models/reschedule-verification.model';
|
||||
import { OtpCheckerGuard } from './core/guards/domain/otp-checker.guard';
|
||||
import { DataSchedulingModel } from './modules/configuration/data-scheduling/data/models/data-scheduling.model';
|
||||
import { DataSchedulingModule } from './modules/configuration/data-scheduling/data-scheduling.module';
|
||||
import { DataSchedulingDefaultModel } from './modules/configuration/data-scheduling/data/models/data-scheduling-default.model';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -176,6 +179,10 @@ import { OtpCheckerGuard } from './core/guards/domain/otp-checker.guard';
|
|||
|
||||
OtpVerificationModel,
|
||||
OtpVerifierModel,
|
||||
|
||||
// Data Scheduling
|
||||
DataSchedulingModel,
|
||||
DataSchedulingDefaultModel,
|
||||
],
|
||||
synchronize: false,
|
||||
}),
|
||||
|
@ -242,6 +249,7 @@ import { OtpCheckerGuard } from './core/guards/domain/otp-checker.guard';
|
|||
BookingOnlineAuthModule,
|
||||
BookingOrderModule,
|
||||
OtpVerificationModule,
|
||||
DataSchedulingModule,
|
||||
],
|
||||
controllers: [],
|
||||
providers: [
|
||||
|
|
|
@ -33,4 +33,6 @@ export enum MODULE_NAME {
|
|||
OTP_VERIFICATIONS = 'otp-verification',
|
||||
|
||||
OTP_VERIFIER = 'otp-verifier',
|
||||
DATA_SCHEDULING = 'data-scheduling',
|
||||
DATA_SCHEDULING_DEFAULT = 'data-scheduling-default',
|
||||
}
|
||||
|
|
|
@ -47,4 +47,6 @@ export enum TABLE_NAME {
|
|||
TIME_GROUPS = 'time_groups',
|
||||
OTP_VERIFICATIONS = 'otp_verifications',
|
||||
OTP_VERIFIER = 'otp_verifier',
|
||||
DATA_SCHEDULING = 'data_scheduling',
|
||||
DATA_SCHEDULING_DEFAULT = 'data_scheduling_default',
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class DataScheduling1751455019718 implements MigrationInterface {
|
||||
name = 'DataScheduling1751455019718';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."data_scheduling_status_enum" AS ENUM('active', 'cancel', 'confirmed', 'draft', 'expired', 'inactive', 'partial refund', 'pending', 'proses refund', 'refunded', 'rejected', 'settled', 'waiting')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "data_scheduling" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "creator_id" character varying(36), "creator_name" character varying(125), "editor_id" character varying(36), "editor_name" character varying(125), "created_at" bigint NOT NULL, "updated_at" bigint NOT NULL, "status" "public"."data_scheduling_status_enum" NOT NULL DEFAULT 'draft', "name" character varying NOT NULL, "indexing_key" character varying NOT NULL, "schedule_date_from" date NOT NULL, "schedule_date_to" date NOT NULL, CONSTRAINT "PK_118219da41190e9b934072b4cc5" PRIMARY KEY ("id"))`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "data_scheduling_default" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "creator_id" character varying(36), "creator_name" character varying(125), "editor_id" character varying(36), "editor_name" character varying(125), "created_at" bigint NOT NULL, "updated_at" bigint NOT NULL, "default_value" integer NOT NULL, CONSTRAINT "PK_c0c3bb2b53c67440a9b534d42b9" PRIMARY KEY ("id"))`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP TABLE "data_scheduling_default"`);
|
||||
await queryRunner.query(`DROP TABLE "data_scheduling"`);
|
||||
await queryRunner.query(`DROP TYPE "public"."data_scheduling_status_enum"`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
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 { DataSchedulingReadOrchestrator } from './domain/usecases/data-scheduling-read.orchestrator';
|
||||
import {
|
||||
DataSchedulingDataController,
|
||||
DataSchedulingDefaultController,
|
||||
DataSchedulingSetupController,
|
||||
} from './infrastructure/data-scheduling-data.controller';
|
||||
import { DataSchedulingDataOrchestrator } from './domain/usecases/data-scheduling-data.orchestrator';
|
||||
import { CreateDataSchedulingManager } from './domain/usecases/managers/create-data-scheduling.manager';
|
||||
import { CqrsModule } from '@nestjs/cqrs';
|
||||
import { IndexDataSchedulingManager } from './domain/usecases/managers/index-data-scheduling.manager';
|
||||
import { DeleteDataSchedulingManager } from './domain/usecases/managers/delete-data-scheduling.manager';
|
||||
import { UpdateDataSchedulingManager } from './domain/usecases/managers/update-data-scheduling.manager';
|
||||
import { ActiveDataSchedulingManager } from './domain/usecases/managers/active-data-scheduling.manager';
|
||||
import { ConfirmDataSchedulingManager } from './domain/usecases/managers/confirm-data-scheduling.manager';
|
||||
import { InactiveDataSchedulingManager } from './domain/usecases/managers/inactive-data-scheduling.manager';
|
||||
import { DetailDataSchedulingManager } from './domain/usecases/managers/detail-data-scheduling.manager';
|
||||
import { BatchDeleteDataSchedulingManager } from './domain/usecases/managers/batch-delete-data-scheduling.manager';
|
||||
import { BatchActiveDataSchedulingManager } from './domain/usecases/managers/batch-active-data-scheduling.manager';
|
||||
import { BatchConfirmDataSchedulingManager } from './domain/usecases/managers/batch-confirm-data-scheduling.manager';
|
||||
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';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
TypeOrmModule.forFeature(
|
||||
[DataSchedulingModel, DataSchedulingDefaultModel],
|
||||
CONNECTION_NAME.DEFAULT,
|
||||
),
|
||||
CqrsModule,
|
||||
],
|
||||
controllers: [
|
||||
DataSchedulingDataController,
|
||||
DataSchedulingReadController,
|
||||
DataSchedulingDefaultController,
|
||||
DataSchedulingSetupController,
|
||||
],
|
||||
providers: [
|
||||
IndexDataSchedulingManager,
|
||||
DetailDataSchedulingManager,
|
||||
CreateDataSchedulingManager,
|
||||
DeleteDataSchedulingManager,
|
||||
UpdateDataSchedulingManager,
|
||||
ActiveDataSchedulingManager,
|
||||
ConfirmDataSchedulingManager,
|
||||
InactiveDataSchedulingManager,
|
||||
BatchDeleteDataSchedulingManager,
|
||||
BatchActiveDataSchedulingManager,
|
||||
BatchConfirmDataSchedulingManager,
|
||||
BatchInactiveDataSchedulingManager,
|
||||
|
||||
DataSchedulingDataService,
|
||||
DataSchedulingReadService,
|
||||
|
||||
DataSchedulingDataOrchestrator,
|
||||
DataSchedulingReadOrchestrator,
|
||||
|
||||
DataSchedulingDefaultManager,
|
||||
],
|
||||
})
|
||||
export class DataSchedulingModule {}
|
|
@ -0,0 +1,13 @@
|
|||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { DataSchedulingDefaultEntity } from '../../domain/entities/data-scheduling.entity';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseModel } from 'src/core/modules/data/model/base.model';
|
||||
|
||||
@Entity(TABLE_NAME.DATA_SCHEDULING_DEFAULT)
|
||||
export class DataSchedulingDefaultModel
|
||||
extends BaseModel<DataSchedulingDefaultEntity>
|
||||
implements DataSchedulingDefaultEntity
|
||||
{
|
||||
@Column('int', { nullable: false })
|
||||
default_value: number;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { DataSchedulingEntity } from '../../domain/entities/data-scheduling.entity';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
|
||||
|
||||
@Entity(TABLE_NAME.DATA_SCHEDULING)
|
||||
export class DataSchedulingModel
|
||||
extends BaseStatusModel<DataSchedulingEntity>
|
||||
implements DataSchedulingEntity
|
||||
{
|
||||
@Column('varchar', { name: 'name' })
|
||||
name: string;
|
||||
|
||||
@Column('varchar', { name: 'indexing_key' })
|
||||
indexing_key: string;
|
||||
|
||||
@Column('date', { name: 'schedule_date_from', nullable: false })
|
||||
schedule_date_from: Date;
|
||||
|
||||
@Column('date', { name: 'schedule_date_to', nullable: false })
|
||||
schedule_date_to: Date;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
||||
import { DataSchedulingEntity } from '../../domain/entities/data-scheduling.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { DataSchedulingModel } from '../models/data-scheduling.model';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class DataSchedulingDataService extends BaseDataService<DataSchedulingEntity> {
|
||||
constructor(
|
||||
@InjectRepository(DataSchedulingModel, CONNECTION_NAME.DEFAULT)
|
||||
private repo: Repository<DataSchedulingModel>,
|
||||
) {
|
||||
super(repo);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { DataSchedulingEntity } from '../../domain/entities/data-scheduling.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { DataSchedulingModel } from '../models/data-scheduling.model';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
|
||||
|
||||
@Injectable()
|
||||
export class DataSchedulingReadService extends BaseReadService<DataSchedulingEntity> {
|
||||
constructor(
|
||||
@InjectRepository(DataSchedulingModel, CONNECTION_NAME.DEFAULT)
|
||||
private repo: Repository<DataSchedulingModel>,
|
||||
) {
|
||||
super(repo);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.entity';
|
||||
import { BaseEntity } from 'src/core/modules/domain/entities/base.entity';
|
||||
|
||||
export interface DataSchedulingEntity extends BaseStatusEntity {
|
||||
name: string;
|
||||
indexing_key: number | string;
|
||||
schedule_date_from: Date;
|
||||
schedule_date_to: Date;
|
||||
}
|
||||
|
||||
export interface DataSchedulingDefaultEntity extends BaseEntity {
|
||||
default_value: number;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
import { IEvent } from 'src/core/strings/constants/interface.constants';
|
||||
|
||||
export class DataSchedulingChangeStatusEvent {
|
||||
constructor(public readonly data: IEvent) {}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
import { IEvent } from 'src/core/strings/constants/interface.constants';
|
||||
|
||||
export class DataSchedulingCreatedEvent {
|
||||
constructor(public readonly data: IEvent) {}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
import { IEvent } from 'src/core/strings/constants/interface.constants';
|
||||
|
||||
export class DataSchedulingDeletedEvent {
|
||||
constructor(public readonly data: IEvent) {}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
import { IEvent } from 'src/core/strings/constants/interface.constants';
|
||||
|
||||
export class DataSchedulingUpdatedEvent {
|
||||
constructor(public readonly data: IEvent) {}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity';
|
||||
|
||||
export interface FilterDataSchedulingEntity extends BaseFilterEntity {
|
||||
schedule_date_from: Date;
|
||||
schedule_date_to: Date;
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { CreateDataSchedulingManager } from './managers/create-data-scheduling.manager';
|
||||
import { DataSchedulingDataService } from '../../data/services/data-scheduling-data.service';
|
||||
import { DataSchedulingEntity } from '../entities/data-scheduling.entity';
|
||||
import { DeleteDataSchedulingManager } from './managers/delete-data-scheduling.manager';
|
||||
import { UpdateDataSchedulingManager } from './managers/update-data-scheduling.manager';
|
||||
import { BaseDataTransactionOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-data-transaction.orchestrator';
|
||||
import { ActiveDataSchedulingManager } from './managers/active-data-scheduling.manager';
|
||||
import { InactiveDataSchedulingManager } from './managers/inactive-data-scheduling.manager';
|
||||
import { ConfirmDataSchedulingManager } from './managers/confirm-data-scheduling.manager';
|
||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||
import { BatchConfirmDataSchedulingManager } from './managers/batch-confirm-data-scheduling.manager';
|
||||
import { BatchInactiveDataSchedulingManager } from './managers/batch-inactive-data-scheduling.manager';
|
||||
import { BatchActiveDataSchedulingManager } from './managers/batch-active-data-scheduling.manager';
|
||||
import { BatchDeleteDataSchedulingManager } from './managers/batch-delete-data-scheduling.manager';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
|
||||
@Injectable()
|
||||
export class DataSchedulingDataOrchestrator extends BaseDataTransactionOrchestrator<DataSchedulingEntity> {
|
||||
constructor(
|
||||
private createManager: CreateDataSchedulingManager,
|
||||
private updateManager: UpdateDataSchedulingManager,
|
||||
private deleteManager: DeleteDataSchedulingManager,
|
||||
private activeManager: ActiveDataSchedulingManager,
|
||||
private confirmManager: ConfirmDataSchedulingManager,
|
||||
private inactiveManager: InactiveDataSchedulingManager,
|
||||
private batchDeleteManager: BatchDeleteDataSchedulingManager,
|
||||
private batchActiveManager: BatchActiveDataSchedulingManager,
|
||||
private batchConfirmManager: BatchConfirmDataSchedulingManager,
|
||||
private batchInactiveManager: BatchInactiveDataSchedulingManager,
|
||||
private serviceData: DataSchedulingDataService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async create(data): Promise<DataSchedulingEntity> {
|
||||
this.createManager.setData(data);
|
||||
this.createManager.setService(this.serviceData, TABLE_NAME.DATA_SCHEDULING);
|
||||
await this.createManager.execute();
|
||||
await this.createManager.generateConfig();
|
||||
return this.createManager.getResult();
|
||||
}
|
||||
|
||||
async update(dataId, data): Promise<DataSchedulingEntity> {
|
||||
this.updateManager.setData(dataId, data);
|
||||
this.updateManager.setService(this.serviceData, TABLE_NAME.DATA_SCHEDULING);
|
||||
await this.updateManager.execute();
|
||||
return this.updateManager.getResult();
|
||||
}
|
||||
|
||||
async delete(dataId): Promise<string> {
|
||||
this.deleteManager.setData(dataId);
|
||||
this.deleteManager.setService(this.serviceData, TABLE_NAME.DATA_SCHEDULING);
|
||||
await this.deleteManager.execute();
|
||||
return this.deleteManager.getResult();
|
||||
}
|
||||
|
||||
async batchDelete(dataIds: string[]): Promise<BatchResult> {
|
||||
this.batchDeleteManager.setData(dataIds);
|
||||
this.batchDeleteManager.setService(
|
||||
this.serviceData,
|
||||
TABLE_NAME.DATA_SCHEDULING,
|
||||
);
|
||||
await this.batchDeleteManager.execute();
|
||||
return this.batchDeleteManager.getResult();
|
||||
}
|
||||
|
||||
async active(dataId): Promise<string> {
|
||||
this.activeManager.setData(dataId, STATUS.ACTIVE);
|
||||
this.activeManager.setService(this.serviceData, TABLE_NAME.DATA_SCHEDULING);
|
||||
await this.activeManager.execute();
|
||||
return this.activeManager.getResult();
|
||||
}
|
||||
|
||||
async batchActive(dataIds: string[]): Promise<BatchResult> {
|
||||
this.batchActiveManager.setData(dataIds, STATUS.ACTIVE);
|
||||
this.batchActiveManager.setService(
|
||||
this.serviceData,
|
||||
TABLE_NAME.DATA_SCHEDULING,
|
||||
);
|
||||
await this.batchActiveManager.execute();
|
||||
return this.batchActiveManager.getResult();
|
||||
}
|
||||
|
||||
async confirm(dataId): Promise<string> {
|
||||
this.confirmManager.setData(dataId, STATUS.ACTIVE);
|
||||
this.confirmManager.setService(
|
||||
this.serviceData,
|
||||
TABLE_NAME.DATA_SCHEDULING,
|
||||
);
|
||||
await this.confirmManager.execute();
|
||||
return this.confirmManager.getResult();
|
||||
}
|
||||
|
||||
async batchConfirm(dataIds: string[]): Promise<BatchResult> {
|
||||
this.batchConfirmManager.setData(dataIds, STATUS.ACTIVE);
|
||||
this.batchConfirmManager.setService(
|
||||
this.serviceData,
|
||||
TABLE_NAME.DATA_SCHEDULING,
|
||||
);
|
||||
await this.batchConfirmManager.execute();
|
||||
return this.batchConfirmManager.getResult();
|
||||
}
|
||||
|
||||
async inactive(dataId): Promise<string> {
|
||||
this.inactiveManager.setData(dataId, STATUS.INACTIVE);
|
||||
this.inactiveManager.setService(
|
||||
this.serviceData,
|
||||
TABLE_NAME.DATA_SCHEDULING,
|
||||
);
|
||||
await this.inactiveManager.execute();
|
||||
return this.inactiveManager.getResult();
|
||||
}
|
||||
|
||||
async batchInactive(dataIds: string[]): Promise<BatchResult> {
|
||||
this.batchInactiveManager.setData(dataIds, STATUS.INACTIVE);
|
||||
this.batchInactiveManager.setService(
|
||||
this.serviceData,
|
||||
TABLE_NAME.DATA_SCHEDULING,
|
||||
);
|
||||
await this.batchInactiveManager.execute();
|
||||
return this.batchInactiveManager.getResult();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
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 { 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';
|
||||
|
||||
@Injectable()
|
||||
export class DataSchedulingReadOrchestrator extends BaseReadOrchestrator<DataSchedulingEntity> {
|
||||
constructor(
|
||||
private indexManager: IndexDataSchedulingManager,
|
||||
private detailManager: DetailDataSchedulingManager,
|
||||
private serviceData: DataSchedulingReadService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async index(params): Promise<PaginationResponse<DataSchedulingEntity>> {
|
||||
this.indexManager.setFilterParam(params);
|
||||
this.indexManager.setService(this.serviceData, TABLE_NAME.DATA_SCHEDULING);
|
||||
await this.indexManager.execute();
|
||||
return this.indexManager.getResult();
|
||||
}
|
||||
|
||||
async detail(dataId: string): Promise<DataSchedulingEntity> {
|
||||
this.detailManager.setData(dataId);
|
||||
this.detailManager.setService(this.serviceData, TABLE_NAME.DATA_SCHEDULING);
|
||||
await this.detailManager.execute();
|
||||
return this.detailManager.getResult();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
|
||||
import { DataSchedulingEntity } from '../../entities/data-scheduling.entity';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { DataSchedulingModel } from '../../../data/models/data-scheduling.model';
|
||||
import { DataSchedulingChangeStatusEvent } from '../../entities/event/data-scheduling-change-status.event';
|
||||
|
||||
@Injectable()
|
||||
export class ActiveDataSchedulingManager extends BaseUpdateStatusManager<DataSchedulingEntity> {
|
||||
getResult(): string {
|
||||
return `Success active data ${this.result.name}`;
|
||||
}
|
||||
|
||||
async validateProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return DataSchedulingModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: DataSchedulingChangeStatusEvent,
|
||||
data: this.data,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager';
|
||||
import { DataSchedulingEntity } from '../../entities/data-scheduling.entity';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { DataSchedulingModel } from '../../../data/models/data-scheduling.model';
|
||||
import { DataSchedulingChangeStatusEvent } from '../../entities/event/data-scheduling-change-status.event';
|
||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class BatchActiveDataSchedulingManager extends BaseBatchUpdateStatusManager<DataSchedulingEntity> {
|
||||
validateData(data: DataSchedulingEntity): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return DataSchedulingModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: DataSchedulingChangeStatusEvent,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
getResult(): BatchResult {
|
||||
return this.result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager';
|
||||
import { DataSchedulingEntity } from '../../entities/data-scheduling.entity';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { DataSchedulingModel } from '../../../data/models/data-scheduling.model';
|
||||
import { DataSchedulingChangeStatusEvent } from '../../entities/event/data-scheduling-change-status.event';
|
||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class BatchConfirmDataSchedulingManager extends BaseBatchUpdateStatusManager<DataSchedulingEntity> {
|
||||
validateData(data: DataSchedulingEntity): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return DataSchedulingModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: DataSchedulingChangeStatusEvent,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
getResult(): BatchResult {
|
||||
return this.result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { BaseBatchDeleteManager } from 'src/core/modules/domain/usecase/managers/base-batch-delete.manager';
|
||||
import { DataSchedulingEntity } from '../../entities/data-scheduling.entity';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { DataSchedulingModel } from '../../../data/models/data-scheduling.model';
|
||||
import { DataSchedulingDeletedEvent } from '../../entities/event/data-scheduling-deleted.event';
|
||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class BatchDeleteDataSchedulingManager extends BaseBatchDeleteManager<DataSchedulingEntity> {
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async validateData(data: DataSchedulingEntity): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return DataSchedulingModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: DataSchedulingDeletedEvent,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
getResult(): BatchResult {
|
||||
return this.result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager';
|
||||
import { DataSchedulingEntity } from '../../entities/data-scheduling.entity';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { DataSchedulingModel } from '../../../data/models/data-scheduling.model';
|
||||
import { DataSchedulingChangeStatusEvent } from '../../entities/event/data-scheduling-change-status.event';
|
||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class BatchInactiveDataSchedulingManager extends BaseBatchUpdateStatusManager<DataSchedulingEntity> {
|
||||
validateData(data: DataSchedulingEntity): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return DataSchedulingModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: DataSchedulingChangeStatusEvent,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
getResult(): BatchResult {
|
||||
return this.result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
|
||||
import { DataSchedulingEntity } from '../../entities/data-scheduling.entity';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { DataSchedulingModel } from '../../../data/models/data-scheduling.model';
|
||||
import { DataSchedulingChangeStatusEvent } from '../../entities/event/data-scheduling-change-status.event';
|
||||
|
||||
@Injectable()
|
||||
export class ConfirmDataSchedulingManager extends BaseUpdateStatusManager<DataSchedulingEntity> {
|
||||
getResult(): string {
|
||||
return `Success active data ${this.result.name}`;
|
||||
}
|
||||
|
||||
async validateProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return DataSchedulingModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: DataSchedulingChangeStatusEvent,
|
||||
data: this.data,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
EventTopics,
|
||||
columnUniques,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { DataSchedulingEntity } from '../../entities/data-scheduling.entity';
|
||||
import { DataSchedulingModel } from '../../../data/models/data-scheduling.model';
|
||||
import { BaseCreateManager } from 'src/core/modules/domain/usecase/managers/base-create.manager';
|
||||
import { DataSchedulingCreatedEvent } from '../../entities/event/data-scheduling-created.event';
|
||||
import { encryptionTotal } from '../../../infrastructure/helpers';
|
||||
import * as moment from 'moment';
|
||||
|
||||
@Injectable()
|
||||
export class CreateDataSchedulingManager extends BaseCreateManager<DataSchedulingEntity> {
|
||||
async beforeProcess(): Promise<void> {
|
||||
const total = this.data.indexing_key;
|
||||
|
||||
if (total > 100) {
|
||||
throw new Error('Maksimal nilai total adalah 100.');
|
||||
}
|
||||
|
||||
const queryBuilder = this.dataService
|
||||
.getRepository()
|
||||
.createQueryBuilder(this.tableName);
|
||||
|
||||
const overlapping = await queryBuilder
|
||||
.where(`${this.tableName}.schedule_date_from <= :schedule_date_to`, {
|
||||
schedule_date_to: this.data.schedule_date_to,
|
||||
})
|
||||
.andWhere(`${this.tableName}.schedule_date_to >= :schedule_date_from`, {
|
||||
schedule_date_from: this.data.schedule_date_from,
|
||||
})
|
||||
.getOne();
|
||||
|
||||
if (this.data) {
|
||||
Object.assign(this.data, {
|
||||
indexing_key: encryptionTotal(total),
|
||||
});
|
||||
}
|
||||
|
||||
console.log(this.data);
|
||||
// Validation date
|
||||
if (overlapping) {
|
||||
throw new Error('Tanggal yang dimasukkan beririsan dengan data lain.');
|
||||
} else if (this.data.schedule_date_from && this.data.schedule_date_to) {
|
||||
const start_time = moment(this.data.schedule_date_from);
|
||||
const end_time = moment(this.data.schedule_date_to);
|
||||
|
||||
if (end_time.isBefore(start_time)) {
|
||||
throw new Error('Tanggal akhir harus lebih besar dari tanggal mulai.');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async generateConfig(): Promise<void> {
|
||||
// TODO: Implement logic here
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get uniqueColumns(): columnUniques[] {
|
||||
return [{ column: 'name' }];
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: DataSchedulingCreatedEvent,
|
||||
data: this.data,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return DataSchedulingModel;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
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 { 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';
|
||||
|
||||
@Injectable()
|
||||
export class DataSchedulingDefaultManager {
|
||||
@Inject()
|
||||
protected userProvider: UserProvider;
|
||||
|
||||
constructor(
|
||||
@InjectRepository(DataSchedulingDefaultModel)
|
||||
private repository: Repository<DataSchedulingDefaultModel>,
|
||||
) {}
|
||||
|
||||
private getUser(): UsersSession {
|
||||
try {
|
||||
return this.userProvider?.user ?? BLANK_USER;
|
||||
} catch (error) {
|
||||
return BLANK_USER;
|
||||
}
|
||||
}
|
||||
|
||||
get tableName(): string {
|
||||
return TABLE_NAME.DATA_SCHEDULING_DEFAULT;
|
||||
}
|
||||
|
||||
private queryBuilder(): SelectQueryBuilder<DataSchedulingDefaultModel> {
|
||||
return this.repository.createQueryBuilder(this.tableName);
|
||||
}
|
||||
|
||||
async update(
|
||||
body: EditDataSchedulingDefaultDto,
|
||||
): Promise<DataSchedulingDefaultEntity> {
|
||||
if (body.default_value > 100) {
|
||||
throw new Error('Value tidak boleh lebih dari 100.');
|
||||
}
|
||||
|
||||
const userData = this.getUser();
|
||||
const dateNow = new Date().getTime();
|
||||
const existData = await this.queryBuilder().getOne();
|
||||
|
||||
const payload: DataSchedulingDefaultEntity = {
|
||||
id: existData?.id,
|
||||
default_value: body.default_value,
|
||||
creator_id: userData.id as any,
|
||||
creator_name: userData.name,
|
||||
editor_id: userData.id as any,
|
||||
editor_name: userData.name,
|
||||
created_at: dateNow,
|
||||
updated_at: dateNow,
|
||||
};
|
||||
|
||||
return this.repository.save(payload);
|
||||
}
|
||||
|
||||
async getData() {
|
||||
return this.queryBuilder().getOne();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseDeleteManager } from 'src/core/modules/domain/usecase/managers/base-delete.manager';
|
||||
import { DataSchedulingEntity } from '../../entities/data-scheduling.entity';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { DataSchedulingModel } from '../../../data/models/data-scheduling.model';
|
||||
import { DataSchedulingDeletedEvent } from '../../entities/event/data-scheduling-deleted.event';
|
||||
|
||||
@Injectable()
|
||||
export class DeleteDataSchedulingManager extends BaseDeleteManager<DataSchedulingEntity> {
|
||||
getResult(): string {
|
||||
return `Success`;
|
||||
}
|
||||
|
||||
async validateProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return DataSchedulingModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: DataSchedulingDeletedEvent,
|
||||
data: this.data,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { BaseDetailManager } from 'src/core/modules/domain/usecase/managers/base-detail.manager';
|
||||
import { DataSchedulingEntity } from '../../entities/data-scheduling.entity';
|
||||
import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity';
|
||||
import { decryptionTotal } from '../../../infrastructure/helpers';
|
||||
|
||||
@Injectable()
|
||||
export class DetailDataSchedulingManager extends BaseDetailManager<DataSchedulingEntity> {
|
||||
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}.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 setFindProperties(): any {
|
||||
return {
|
||||
id: this.dataId,
|
||||
};
|
||||
}
|
||||
|
||||
getResult(): DataSchedulingEntity {
|
||||
if (!this.result) throw new NotFoundException('Data not found.');
|
||||
|
||||
const total = decryptionTotal(this.result.indexing_key as string);
|
||||
return {
|
||||
...this.result,
|
||||
indexing_key: total,
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
|
||||
import { DataSchedulingEntity } from '../../entities/data-scheduling.entity';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { DataSchedulingModel } from '../../../data/models/data-scheduling.model';
|
||||
import { DataSchedulingChangeStatusEvent } from '../../entities/event/data-scheduling-change-status.event';
|
||||
|
||||
@Injectable()
|
||||
export class InactiveDataSchedulingManager extends BaseUpdateStatusManager<DataSchedulingEntity> {
|
||||
getResult(): string {
|
||||
return `Success inactive data ${this.result.name}`;
|
||||
}
|
||||
|
||||
async validateProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return DataSchedulingModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: DataSchedulingChangeStatusEvent,
|
||||
data: this.data,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager';
|
||||
import { DataSchedulingEntity } 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 IndexDataSchedulingManager extends BaseIndexManager<DataSchedulingEntity> {
|
||||
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}.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<DataSchedulingEntity>,
|
||||
): SelectQueryBuilder<DataSchedulingEntity> {
|
||||
return queryBuilder;
|
||||
}
|
||||
|
||||
getResult(): PaginationResponse<DataSchedulingEntity> {
|
||||
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 };
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseUpdateManager } from 'src/core/modules/domain/usecase/managers/base-update.manager';
|
||||
import { DataSchedulingEntity } from '../../entities/data-scheduling.entity';
|
||||
import { DataSchedulingModel } from '../../../data/models/data-scheduling.model';
|
||||
import { DataSchedulingUpdatedEvent } from '../../entities/event/data-scheduling-updated.event';
|
||||
import {
|
||||
EventTopics,
|
||||
columnUniques,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { encryptionTotal } from '../../../infrastructure/helpers';
|
||||
|
||||
@Injectable()
|
||||
export class UpdateDataSchedulingManager extends BaseUpdateManager<DataSchedulingEntity> {
|
||||
async validateProcess(): Promise<void> {
|
||||
const total = this.data.indexing_key;
|
||||
|
||||
if (total > 100) {
|
||||
throw new Error('Maksimal nilai total adalah 100.');
|
||||
}
|
||||
|
||||
const queryBuilder = this.dataService
|
||||
.getRepository()
|
||||
.createQueryBuilder(this.tableName);
|
||||
|
||||
const overlapping = await queryBuilder
|
||||
.where(`${this.tableName}.schedule_date_from <= :schedule_date_to`, {
|
||||
schedule_date_to: this.data.schedule_date_to,
|
||||
})
|
||||
.andWhere(`${this.tableName}.schedule_date_to >= :schedule_date_from`, {
|
||||
schedule_date_from: this.data.schedule_date_from,
|
||||
})
|
||||
.andWhere(`${this.tableName}.id != :id`, { id: this.dataId ?? null })
|
||||
.getOne();
|
||||
|
||||
// Validation date
|
||||
if (overlapping) {
|
||||
throw new Error('Tanggal yang dimasukkan tidak boleh sama.');
|
||||
} else {
|
||||
//Encryption total data
|
||||
Object.assign(this.data, {
|
||||
indexing_key: encryptionTotal(total),
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get uniqueColumns(): columnUniques[] {
|
||||
return [{ column: 'name' }];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return DataSchedulingModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: DataSchedulingUpdatedEvent,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
Put,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { DataSchedulingDataOrchestrator } from '../domain/usecases/data-scheduling-data.orchestrator';
|
||||
import {
|
||||
SetupDataSchedulingDto,
|
||||
CreateDataSchedulingDto,
|
||||
EditDataSchedulingDto,
|
||||
EditDataSchedulingDefaultDto,
|
||||
} from './dto/data-scheduling.dto';
|
||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import {
|
||||
DataSchedulingDefaultEntity,
|
||||
DataSchedulingEntity,
|
||||
} from '../domain/entities/data-scheduling.entity';
|
||||
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 { get } from 'http';
|
||||
|
||||
@ApiTags(`${MODULE_NAME.DATA_SCHEDULING.split('-').join(' ')} - data`)
|
||||
@Controller(`v1/${MODULE_NAME.DATA_SCHEDULING}`)
|
||||
@Public(false)
|
||||
@ApiBearerAuth('JWT')
|
||||
export class DataSchedulingDataController {
|
||||
constructor(private orchestrator: DataSchedulingDataOrchestrator) {}
|
||||
|
||||
@Post()
|
||||
async create(
|
||||
@Body() data: CreateDataSchedulingDto,
|
||||
): Promise<DataSchedulingEntity> {
|
||||
return await this.orchestrator.create(data);
|
||||
}
|
||||
|
||||
@Put('/batch-delete')
|
||||
async batchDeleted(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||
return await this.orchestrator.batchDelete(body.ids);
|
||||
}
|
||||
|
||||
@Patch(':id/active')
|
||||
async active(@Param('id') dataId: string): Promise<string> {
|
||||
return await this.orchestrator.active(dataId);
|
||||
}
|
||||
|
||||
@Put('/batch-active')
|
||||
async batchActive(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||
return await this.orchestrator.batchActive(body.ids);
|
||||
}
|
||||
|
||||
@Patch(':id/confirm')
|
||||
async confirm(@Param('id') dataId: string): Promise<string> {
|
||||
return await this.orchestrator.confirm(dataId);
|
||||
}
|
||||
|
||||
@Put('/batch-confirm')
|
||||
async batchConfirm(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||
return await this.orchestrator.batchConfirm(body.ids);
|
||||
}
|
||||
|
||||
@Patch(':id/inactive')
|
||||
async inactive(@Param('id') dataId: string): Promise<string> {
|
||||
return await this.orchestrator.inactive(dataId);
|
||||
}
|
||||
|
||||
@Put('/batch-inactive')
|
||||
async batchInactive(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||
return await this.orchestrator.batchInactive(body.ids);
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
async update(
|
||||
@Param('id') dataId: string,
|
||||
@Body() data: EditDataSchedulingDto,
|
||||
): Promise<DataSchedulingEntity> {
|
||||
return await this.orchestrator.update(dataId, data);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async delete(@Param('id') dataId: string): Promise<string> {
|
||||
return await this.orchestrator.delete(dataId);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiTags(
|
||||
`${MODULE_NAME.DATA_SCHEDULING_DEFAULT.split('-').join(' ')} setup - Data`,
|
||||
)
|
||||
@Controller(`v1/${MODULE_NAME.DATA_SCHEDULING_DEFAULT}`)
|
||||
@Public(false)
|
||||
@ApiBearerAuth('JWT')
|
||||
export class DataSchedulingDefaultController {
|
||||
constructor(private manager: DataSchedulingDefaultManager) {}
|
||||
@Post()
|
||||
async create(
|
||||
@Body() data: EditDataSchedulingDefaultDto,
|
||||
): Promise<DataSchedulingDefaultEntity> {
|
||||
return await this.manager.update(data);
|
||||
}
|
||||
|
||||
@Get()
|
||||
async get(): Promise<DataSchedulingDefaultEntity> {
|
||||
console.log('here');
|
||||
return await this.manager.getData();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiTags(`${MODULE_NAME.DATA_SCHEDULING.split('-').join(' ')} setup - Data`)
|
||||
@Controller(``)
|
||||
@Public(true)
|
||||
export class DataSchedulingSetupController {
|
||||
@Post('v1/data-scheduling-setup')
|
||||
@ExcludePrivilege()
|
||||
@UseGuards(SetupSchedulingGuard)
|
||||
async setup(
|
||||
@Body() data: SetupDataSchedulingDto,
|
||||
): Promise<DataSchedulingEntity> {
|
||||
console.log('payload scheduling setup', { data });
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
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 { 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';
|
||||
|
||||
@ApiTags(`${MODULE_NAME.DATA_SCHEDULING.split('-').join(' ')} - read`)
|
||||
@Controller(`v1/${MODULE_NAME.DATA_SCHEDULING}`)
|
||||
@Public(false)
|
||||
@ApiBearerAuth('JWT')
|
||||
export class DataSchedulingReadController {
|
||||
constructor(private orchestrator: DataSchedulingReadOrchestrator) {}
|
||||
|
||||
@Get()
|
||||
@Pagination()
|
||||
async index(
|
||||
@Query() params: FilterDataSchedulingDto,
|
||||
): Promise<PaginationResponse<DataSchedulingEntity>> {
|
||||
return await this.orchestrator.index(params);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async detail(@Param('id') id: string): Promise<DataSchedulingEntity> {
|
||||
return await this.orchestrator.detail(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
import { BaseStatusDto } from 'src/core/modules/infrastructure/dto/base-status.dto';
|
||||
import {
|
||||
DataSchedulingDefaultEntity,
|
||||
DataSchedulingEntity,
|
||||
} from '../../domain/entities/data-scheduling.entity';
|
||||
import { IsString, ValidateIf } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { BaseCoreDto } from 'src/core/modules/infrastructure/dto/base-core.dto';
|
||||
import { Transform } from 'class-transformer';
|
||||
import { BaseDto } from 'src/core/modules/infrastructure/dto/base.dto';
|
||||
|
||||
export class CreateDataSchedulingDto
|
||||
extends BaseStatusDto
|
||||
implements DataSchedulingEntity
|
||||
{
|
||||
@ApiProperty({ name: 'name', required: true, example: 'Morning' })
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@ApiProperty({ type: 'integer', required: true, example: 80 })
|
||||
@Transform((body) => {
|
||||
return typeof body.value == 'string' ? Number(body.value) : body.value;
|
||||
})
|
||||
@ValidateIf((body) => body.indexing_key)
|
||||
indexing_key: number;
|
||||
|
||||
@ApiProperty({
|
||||
type: Date,
|
||||
required: true,
|
||||
example: '2024-01-01',
|
||||
})
|
||||
schedule_date_from: Date;
|
||||
|
||||
@ApiProperty({
|
||||
type: Date,
|
||||
required: true,
|
||||
example: '2024-01-02',
|
||||
})
|
||||
schedule_date_to: Date;
|
||||
}
|
||||
|
||||
export class EditDataSchedulingDto
|
||||
extends BaseStatusDto
|
||||
implements DataSchedulingEntity
|
||||
{
|
||||
@ApiProperty({ name: 'name', example: 'Morning' })
|
||||
@IsString()
|
||||
@ValidateIf((body) => body.name)
|
||||
name: string;
|
||||
|
||||
@ApiProperty({ type: 'integer', required: true, example: 80 })
|
||||
@Transform((body) => {
|
||||
return typeof body.value == 'string' ? Number(body.value) : body.value;
|
||||
})
|
||||
@ValidateIf((body) => body.indexing_key)
|
||||
indexing_key: number;
|
||||
|
||||
@ApiProperty({
|
||||
type: Date,
|
||||
required: true,
|
||||
example: '2025-01-01',
|
||||
})
|
||||
schedule_date_from: Date;
|
||||
|
||||
@ApiProperty({
|
||||
type: Date,
|
||||
required: true,
|
||||
example: '2025-01-02',
|
||||
})
|
||||
schedule_date_to: Date;
|
||||
}
|
||||
|
||||
export class EditDataSchedulingDefaultDto
|
||||
extends BaseDto
|
||||
implements DataSchedulingDefaultEntity
|
||||
{
|
||||
@ApiProperty({ type: 'integer', required: true })
|
||||
@Transform((body) => {
|
||||
return typeof body.value == 'string' ? Number(body.value) : body.value;
|
||||
})
|
||||
@ValidateIf((body) => body.default_value)
|
||||
default_value: number;
|
||||
}
|
||||
|
||||
export class SetupDataSchedulingDto {
|
||||
@ApiProperty({
|
||||
type: Date,
|
||||
required: true,
|
||||
example: '2024-01-01',
|
||||
})
|
||||
schedule_date: Date;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
import { BaseFilterDto } from 'src/core/modules/infrastructure/dto/base-filter.dto';
|
||||
import { FilterDataSchedulingEntity } from '../../domain/entities/filter-data-scheduling.entity';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { ValidateIf } from 'class-validator';
|
||||
|
||||
export class FilterDataSchedulingDto
|
||||
extends BaseFilterDto
|
||||
implements FilterDataSchedulingEntity
|
||||
{
|
||||
@ApiProperty({ type: 'string', required: false })
|
||||
@ValidateIf((body) => body.schedule_date_from)
|
||||
schedule_date_from: Date;
|
||||
|
||||
@ApiProperty({ type: 'string', required: false })
|
||||
@ValidateIf((body) => body.schedule_date_to)
|
||||
schedule_date_to: Date;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
import {
|
||||
CanActivate,
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
UnprocessableEntityException,
|
||||
} from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class SetupSchedulingGuard implements CanActivate {
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const setupAuth = request.headers['x-setup-authorization'];
|
||||
|
||||
if (setupAuth) {
|
||||
try {
|
||||
const setupKey = process.env.SETUP_SCHEDULING_KEY;
|
||||
if (setupAuth === setupKey) return true;
|
||||
else new UnprocessableEntityException('Setup Authorization Not Found.');
|
||||
} catch (err) {
|
||||
throw new UnprocessableEntityException('Invalid authentication.');
|
||||
}
|
||||
}
|
||||
|
||||
throw new UnprocessableEntityException('Invalid authentication');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
export function encryptionTotal(total: number): string {
|
||||
return btoa(total.toString());
|
||||
}
|
||||
|
||||
export function decryptionTotal(total: string): number {
|
||||
return Number(atob(total));
|
||||
}
|
Loading…
Reference in New Issue