feat(SPG-335) REST API CRUD Item Category
parent
417e90dbc5
commit
14559290cf
|
@ -19,6 +19,9 @@ import { LogModel } from './modules/configuration/log/data/models/log.model';
|
||||||
import { ErrorLogModel } from './modules/configuration/log/data/models/error-log.model';
|
import { ErrorLogModel } from './modules/configuration/log/data/models/error-log.model';
|
||||||
import { LogModule } from './modules/configuration/log/log.module';
|
import { LogModule } from './modules/configuration/log/log.module';
|
||||||
import { TenantModule } from './modules/user-related/tenant/tenant.module';
|
import { TenantModule } from './modules/user-related/tenant/tenant.module';
|
||||||
|
import { ItemCategoryModule } from './modules/item-related/item-category/item-category.module';
|
||||||
|
import { ItemCategoryModel } from './modules/item-related/item-category/data/models/item-category.model';
|
||||||
|
import { ConstantModule } from './modules/configuration/constant/constant.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -34,18 +37,27 @@ import { TenantModule } from './modules/user-related/tenant/tenant.module';
|
||||||
username: process.env.DEFAULT_DB_USER,
|
username: process.env.DEFAULT_DB_USER,
|
||||||
password: process.env.DEFAULT_DB_PASS,
|
password: process.env.DEFAULT_DB_PASS,
|
||||||
database: process.env.DEFAULT_DB_NAME,
|
database: process.env.DEFAULT_DB_NAME,
|
||||||
entities: [...UserPrivilegeModels, UserModel, LogModel, ErrorLogModel],
|
entities: [
|
||||||
|
...UserPrivilegeModels,
|
||||||
|
UserModel,
|
||||||
|
LogModel,
|
||||||
|
ErrorLogModel,
|
||||||
|
ItemCategoryModel,
|
||||||
|
],
|
||||||
synchronize: false,
|
synchronize: false,
|
||||||
}),
|
}),
|
||||||
|
ConstantModule,
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
SessionModule,
|
SessionModule,
|
||||||
AuthModule,
|
AuthModule,
|
||||||
CouchModule,
|
CouchModule,
|
||||||
LogModule,
|
LogModule,
|
||||||
|
|
||||||
UserModule,
|
|
||||||
TenantModule,
|
TenantModule,
|
||||||
|
UserModule,
|
||||||
UserPrivilegeModule,
|
UserPrivilegeModule,
|
||||||
|
|
||||||
|
ItemCategoryModule,
|
||||||
],
|
],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
providers: [
|
providers: [
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
export enum MODULE_NAME {
|
export enum MODULE_NAME {
|
||||||
|
ITEM_CATEGORY = 'item-categories',
|
||||||
TENANT = 'tenants',
|
TENANT = 'tenants',
|
||||||
USER = 'users',
|
USER = 'users',
|
||||||
USER_PRIVILEGE = 'user-privileges',
|
USER_PRIVILEGE = 'user-privileges',
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
export enum TABLE_NAME {
|
export enum TABLE_NAME {
|
||||||
LOG = 'logs',
|
|
||||||
ERROR_LOG = 'log_errors',
|
ERROR_LOG = 'log_errors',
|
||||||
USER = 'users',
|
ITEM_CATEGORY = 'item_categories',
|
||||||
|
LOG = 'logs',
|
||||||
TENANT = 'tenants',
|
TENANT = 'tenants',
|
||||||
|
USER = 'users',
|
||||||
USER_PRIVILEGE = 'user_privileges',
|
USER_PRIVILEGE = 'user_privileges',
|
||||||
USER_PRIVILEGE_CONFIGURATION = 'user_privilege_configurations',
|
USER_PRIVILEGE_CONFIGURATION = 'user_privilege_configurations',
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class ItemCategory1718005501425 implements MigrationInterface {
|
||||||
|
name = 'ItemCategory1718005501425';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TYPE "public"."item_categories_status_enum" AS ENUM('active', 'cancel', 'confirmed', 'draft', 'expired', 'inactive', 'pending', 'refunded', 'rejected', 'settled', 'waiting')`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TYPE "public"."item_categories_item_type_enum" AS ENUM('tiket masuk', 'wahana', 'bundling', 'free gift')`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TABLE "item_categories" ("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"."item_categories_status_enum" NOT NULL DEFAULT 'draft', "name" character varying NOT NULL, "item_type" "public"."item_categories_item_type_enum" NOT NULL DEFAULT 'tiket masuk', CONSTRAINT "PK_db3359595abacbe15cf2f89c07e" PRIMARY KEY ("id"))`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`DROP TABLE "item_categories"`);
|
||||||
|
await queryRunner.query(
|
||||||
|
`DROP TYPE "public"."item_categories_item_type_enum"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(`DROP TYPE "public"."item_categories_status_enum"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import { ConstantController } from './infrastructure/constant.controller';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [ConfigModule.forRoot()],
|
||||||
|
controllers: [ConstantController],
|
||||||
|
providers: [],
|
||||||
|
})
|
||||||
|
export class ConstantModule {}
|
|
@ -0,0 +1,22 @@
|
||||||
|
import { Controller, Get } from '@nestjs/common';
|
||||||
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
|
import { Public } from 'src/core/guards';
|
||||||
|
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { ItemType } from 'src/modules/item-related/item-category/constants';
|
||||||
|
|
||||||
|
@ApiTags('configuration - constant')
|
||||||
|
@Controller('constant')
|
||||||
|
@Public(true)
|
||||||
|
export class ConstantController {
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
@Get('master-data-status')
|
||||||
|
async masterDataStatus(): Promise<any> {
|
||||||
|
return [STATUS.ACTIVE, STATUS.DRAFT, STATUS.INACTIVE];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('category-item-type')
|
||||||
|
async categoryType(): Promise<any> {
|
||||||
|
return Object.values(ItemType);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
export enum ItemType {
|
||||||
|
TIKET_MASUK = 'tiket masuk',
|
||||||
|
WAHANA = 'wahana',
|
||||||
|
BUNDLING = 'bundling',
|
||||||
|
FREE_GIFT = 'free gift',
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
import { ItemCategoryEntity } from '../../domain/entities/item-category.entity';
|
||||||
|
import { Column, Entity } from 'typeorm';
|
||||||
|
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
|
||||||
|
import { ItemType } from '../../constants';
|
||||||
|
|
||||||
|
@Entity(TABLE_NAME.ITEM_CATEGORY)
|
||||||
|
export class ItemCategoryModel
|
||||||
|
extends BaseStatusModel<ItemCategoryEntity>
|
||||||
|
implements ItemCategoryEntity
|
||||||
|
{
|
||||||
|
@Column('varchar', { name: 'name' })
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@Column('enum', {
|
||||||
|
name: 'item_type',
|
||||||
|
enum: ItemType,
|
||||||
|
default: ItemType.TIKET_MASUK,
|
||||||
|
})
|
||||||
|
item_type: ItemType;
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
||||||
|
import { ItemCategoryEntity } from '../../domain/entities/item-category.entity';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { ItemCategoryModel } from '../models/item-category.model';
|
||||||
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { Repository } from 'typeorm';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ItemCategoryDataService extends BaseDataService<ItemCategoryEntity> {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(ItemCategoryModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private repo: Repository<ItemCategoryModel>,
|
||||||
|
) {
|
||||||
|
super(repo);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { IEvent } from 'src/core/strings/constants/interface.constants';
|
||||||
|
|
||||||
|
export class ItemCategoryChangeStatusEvent {
|
||||||
|
constructor(public readonly data: IEvent) {}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { IEvent } from 'src/core/strings/constants/interface.constants';
|
||||||
|
|
||||||
|
export class ItemCategoryCreatedEvent {
|
||||||
|
constructor(public readonly data: IEvent) {}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { IEvent } from 'src/core/strings/constants/interface.constants';
|
||||||
|
|
||||||
|
export class ItemCategoryDeletedEvent {
|
||||||
|
constructor(public readonly data: IEvent) {}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { IEvent } from 'src/core/strings/constants/interface.constants';
|
||||||
|
|
||||||
|
export class ItemCategoryUpdatedEvent {
|
||||||
|
constructor(public readonly data: IEvent) {}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.entity';
|
||||||
|
import { ItemType } from '../../constants';
|
||||||
|
|
||||||
|
export interface ItemCategoryEntity extends BaseStatusEntity {
|
||||||
|
name: string;
|
||||||
|
item_type: ItemType;
|
||||||
|
}
|
|
@ -0,0 +1,119 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { CreateItemCategoryManager } from './managers/create-item-category.manager';
|
||||||
|
import { ItemCategoryDataService } from '../../data/services/item-category-data.service';
|
||||||
|
import { ItemCategoryEntity } from '../entities/item-category.entity';
|
||||||
|
import { DeleteItemCategoryManager } from './managers/delete-item-category.manager';
|
||||||
|
import { UpdateItemCategoryManager } from './managers/update-item-category.manager';
|
||||||
|
import { BaseDataTransactionOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-data-transaction.orchestrator';
|
||||||
|
import { ActiveItemCategoryManager } from './managers/active-item-category.manager';
|
||||||
|
import { InactiveItemCategoryManager } from './managers/inactive-item-category.manager';
|
||||||
|
import { ConfirmItemCategoryManager } from './managers/confirm-item-category.manager';
|
||||||
|
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { BatchConfirmItemCategoryManager } from './managers/batch-confirm-item-category.manager';
|
||||||
|
import { BatchInactiveItemCategoryManager } from './managers/batch-inactive-item-category.manager';
|
||||||
|
import { BatchActiveItemCategoryManager } from './managers/batch-active-item-category.manager';
|
||||||
|
import { BatchDeleteItemCategoryManager } from './managers/batch-delete-item-category.manager';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ItemCategoryDataOrchestrator extends BaseDataTransactionOrchestrator<ItemCategoryEntity> {
|
||||||
|
constructor(
|
||||||
|
private createManager: CreateItemCategoryManager,
|
||||||
|
private updateManager: UpdateItemCategoryManager,
|
||||||
|
private deleteManager: DeleteItemCategoryManager,
|
||||||
|
private activeManager: ActiveItemCategoryManager,
|
||||||
|
private confirmManager: ConfirmItemCategoryManager,
|
||||||
|
private inactiveManager: InactiveItemCategoryManager,
|
||||||
|
private batchDeleteManager: BatchDeleteItemCategoryManager,
|
||||||
|
private batchActiveManager: BatchActiveItemCategoryManager,
|
||||||
|
private batchConfirmManager: BatchConfirmItemCategoryManager,
|
||||||
|
private batchInactiveManager: BatchInactiveItemCategoryManager,
|
||||||
|
private serviceData: ItemCategoryDataService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(data): Promise<ItemCategoryEntity> {
|
||||||
|
this.createManager.setData(data);
|
||||||
|
this.createManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY);
|
||||||
|
await this.createManager.execute();
|
||||||
|
await this.createManager.generateConfig();
|
||||||
|
return this.createManager.getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(dataId, data): Promise<ItemCategoryEntity> {
|
||||||
|
this.updateManager.setData(dataId, data);
|
||||||
|
this.updateManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY);
|
||||||
|
await this.updateManager.execute();
|
||||||
|
return this.updateManager.getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
async delete(dataId): Promise<String> {
|
||||||
|
this.deleteManager.setData(dataId);
|
||||||
|
this.deleteManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY);
|
||||||
|
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.ITEM_CATEGORY,
|
||||||
|
);
|
||||||
|
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.ITEM_CATEGORY);
|
||||||
|
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.ITEM_CATEGORY,
|
||||||
|
);
|
||||||
|
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.ITEM_CATEGORY);
|
||||||
|
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.ITEM_CATEGORY,
|
||||||
|
);
|
||||||
|
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.ITEM_CATEGORY);
|
||||||
|
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.ITEM_CATEGORY,
|
||||||
|
);
|
||||||
|
await this.batchInactiveManager.execute();
|
||||||
|
return this.batchInactiveManager.getResult();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
|
||||||
|
import { ItemCategoryEntity } from '../../entities/item-category.entity';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemCategoryModel } from '../../../data/models/item-category.model';
|
||||||
|
import { ItemCategoryChangeStatusEvent } from '../../entities/event/item-category-change-status.event';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ActiveItemCategoryManager extends BaseUpdateStatusManager<ItemCategoryEntity> {
|
||||||
|
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 ItemCategoryModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
topic: ItemCategoryChangeStatusEvent,
|
||||||
|
data: this.data,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager';
|
||||||
|
import { ItemCategoryEntity } from '../../entities/item-category.entity';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemCategoryModel } from '../../../data/models/item-category.model';
|
||||||
|
import { ItemCategoryChangeStatusEvent } from '../../entities/event/item-category-change-status.event';
|
||||||
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BatchActiveItemCategoryManager extends BaseBatchUpdateStatusManager<ItemCategoryEntity> {
|
||||||
|
validateData(data: ItemCategoryEntity): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get validateRelations(): validateRelations[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
get entityTarget(): any {
|
||||||
|
return ItemCategoryModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
topic: ItemCategoryChangeStatusEvent,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
getResult(): BatchResult {
|
||||||
|
return this.result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager';
|
||||||
|
import { ItemCategoryEntity } from '../../entities/item-category.entity';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemCategoryModel } from '../../../data/models/item-category.model';
|
||||||
|
import { ItemCategoryChangeStatusEvent } from '../../entities/event/item-category-change-status.event';
|
||||||
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BatchConfirmItemCategoryManager extends BaseBatchUpdateStatusManager<ItemCategoryEntity> {
|
||||||
|
validateData(data: ItemCategoryEntity): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get validateRelations(): validateRelations[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
get entityTarget(): any {
|
||||||
|
return ItemCategoryModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
topic: ItemCategoryChangeStatusEvent,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
getResult(): BatchResult {
|
||||||
|
return this.result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { BaseBatchDeleteManager } from 'src/core/modules/domain/usecase/managers/base-batch-delete.manager';
|
||||||
|
import { ItemCategoryEntity } from '../../entities/item-category.entity';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemCategoryModel } from '../../../data/models/item-category.model';
|
||||||
|
import { ItemCategoryDeletedEvent } from '../../entities/event/item-category-deleted.event';
|
||||||
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BatchDeleteItemCategoryManager extends BaseBatchDeleteManager<ItemCategoryEntity> {
|
||||||
|
async beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async validateData(data: ItemCategoryEntity): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get validateRelations(): validateRelations[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
get entityTarget(): any {
|
||||||
|
return ItemCategoryModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
topic: ItemCategoryDeletedEvent,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
getResult(): BatchResult {
|
||||||
|
return this.result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager';
|
||||||
|
import { ItemCategoryEntity } from '../../entities/item-category.entity';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemCategoryModel } from '../../../data/models/item-category.model';
|
||||||
|
import { ItemCategoryChangeStatusEvent } from '../../entities/event/item-category-change-status.event';
|
||||||
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BatchInactiveItemCategoryManager extends BaseBatchUpdateStatusManager<ItemCategoryEntity> {
|
||||||
|
validateData(data: ItemCategoryEntity): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get validateRelations(): validateRelations[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
get entityTarget(): any {
|
||||||
|
return ItemCategoryModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
topic: ItemCategoryChangeStatusEvent,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
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 { ItemCategoryEntity } from '../../entities/item-category.entity';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemCategoryModel } from '../../../data/models/item-category.model';
|
||||||
|
import { ItemCategoryChangeStatusEvent } from '../../entities/event/item-category-change-status.event';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ConfirmItemCategoryManager extends BaseUpdateStatusManager<ItemCategoryEntity> {
|
||||||
|
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 ItemCategoryModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
topic: ItemCategoryChangeStatusEvent,
|
||||||
|
data: this.data,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
columnUniques,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemCategoryEntity } from '../../entities/item-category.entity';
|
||||||
|
import { ItemCategoryModel } from '../../../data/models/item-category.model';
|
||||||
|
import { BaseCreateManager } from 'src/core/modules/domain/usecase/managers/base-create.manager';
|
||||||
|
import { ItemCategoryCreatedEvent } from '../../entities/event/item-category-created.event';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class CreateItemCategoryManager extends BaseCreateManager<ItemCategoryEntity> {
|
||||||
|
async beforeProcess(): Promise<void> {
|
||||||
|
Object.assign(this.data, {
|
||||||
|
item_type: this.data.item_type.toLowerCase(),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async generateConfig(): Promise<void> {}
|
||||||
|
|
||||||
|
get validateRelations(): validateRelations[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
get uniqueColumns(): columnUniques[] {
|
||||||
|
return [{ column: 'name' }];
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
topic: ItemCategoryCreatedEvent,
|
||||||
|
data: this.data,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
get entityTarget(): any {
|
||||||
|
return ItemCategoryModel;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseDeleteManager } from 'src/core/modules/domain/usecase/managers/base-delete.manager';
|
||||||
|
import { ItemCategoryEntity } from '../../entities/item-category.entity';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemCategoryModel } from '../../../data/models/item-category.model';
|
||||||
|
import { ItemCategoryDeletedEvent } from '../../entities/event/item-category-deleted.event';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class DeleteItemCategoryManager extends BaseDeleteManager<ItemCategoryEntity> {
|
||||||
|
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 ItemCategoryModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
topic: ItemCategoryDeletedEvent,
|
||||||
|
data: this.data,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
|
||||||
|
import { ItemCategoryEntity } from '../../entities/item-category.entity';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemCategoryModel } from '../../../data/models/item-category.model';
|
||||||
|
import { ItemCategoryChangeStatusEvent } from '../../entities/event/item-category-change-status.event';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class InactiveItemCategoryManager extends BaseUpdateStatusManager<ItemCategoryEntity> {
|
||||||
|
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 ItemCategoryModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
topic: ItemCategoryChangeStatusEvent,
|
||||||
|
data: this.data,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseUpdateManager } from 'src/core/modules/domain/usecase/managers/base-update.manager';
|
||||||
|
import { ItemCategoryEntity } from '../../entities/item-category.entity';
|
||||||
|
import { ItemCategoryModel } from '../../../data/models/item-category.model';
|
||||||
|
import { ItemCategoryUpdatedEvent } from '../../entities/event/item-category-updated.event';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
columnUniques,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class UpdateItemCategoryManager extends BaseUpdateManager<ItemCategoryEntity> {
|
||||||
|
async validateProcess(): Promise<void> {
|
||||||
|
Object.assign(this.data, {
|
||||||
|
item_type: this.data.item_type.toLowerCase(),
|
||||||
|
});
|
||||||
|
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 ItemCategoryModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
topic: ItemCategoryUpdatedEvent,
|
||||||
|
data: this.data,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
import { BaseStatusDto } from 'src/core/modules/infrastructure/dto/base-status.dto';
|
||||||
|
import { ItemCategoryEntity } from '../../domain/entities/item-category.entity';
|
||||||
|
import { IsEnum, IsString, ValidateIf } from 'class-validator';
|
||||||
|
import { ItemType } from '../../constants';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
export class ItemCategoryDto
|
||||||
|
extends BaseStatusDto
|
||||||
|
implements ItemCategoryEntity
|
||||||
|
{
|
||||||
|
@ApiProperty({ name: 'name', required: true, example: 'Bundling w Entrance' })
|
||||||
|
@IsString()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
description: `Select (${JSON.stringify(Object.values(ItemType))})`,
|
||||||
|
example: ItemType.BUNDLING,
|
||||||
|
})
|
||||||
|
@ValidateIf((body) => body.order_type)
|
||||||
|
@IsEnum(ItemType, {
|
||||||
|
message: `must be a valid enum ${JSON.stringify(Object.values(ItemType))}`,
|
||||||
|
})
|
||||||
|
item_type: ItemType;
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Delete,
|
||||||
|
Param,
|
||||||
|
Patch,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { ItemCategoryDataOrchestrator } from '../domain/usecases/item-category-data.orchestrator';
|
||||||
|
import { ItemCategoryDto } from './dto/item-category.dto';
|
||||||
|
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||||
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
|
import { ItemCategoryEntity } from '../domain/entities/item-category.entity';
|
||||||
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
|
||||||
|
import { Public } from 'src/core/guards';
|
||||||
|
|
||||||
|
@ApiTags(`${MODULE_NAME.ITEM_CATEGORY.split('-').join(' ')} - data`)
|
||||||
|
@Controller(MODULE_NAME.ITEM_CATEGORY)
|
||||||
|
@Public(false)
|
||||||
|
@ApiBearerAuth('JWT')
|
||||||
|
export class ItemCategoryDataController {
|
||||||
|
constructor(private orchestrator: ItemCategoryDataOrchestrator) {}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
async create(@Body() data: ItemCategoryDto): Promise<ItemCategoryEntity> {
|
||||||
|
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: ItemCategoryDto,
|
||||||
|
): Promise<ItemCategoryEntity> {
|
||||||
|
return await this.orchestrator.update(dataId, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete(':id')
|
||||||
|
async delete(@Param('id') dataId: string): Promise<String> {
|
||||||
|
return await this.orchestrator.delete(dataId);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
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 { ItemCategoryDataService } from './data/services/item-category-data.service';
|
||||||
|
import { ItemCategoryReadService } from './data/services/item-category-read.service';
|
||||||
|
import { ItemCategoryReadController } from './infrastructure/item-category-read.controller';
|
||||||
|
import { ItemCategoryReadOrchestrator } from './domain/usecases/item-category-read.orchestrator';
|
||||||
|
import { ItemCategoryDataController } from './infrastructure/item-category-data.controller';
|
||||||
|
import { ItemCategoryDataOrchestrator } from './domain/usecases/item-category-data.orchestrator';
|
||||||
|
import { CreateItemCategoryManager } from './domain/usecases/managers/create-item-category.manager';
|
||||||
|
import { CqrsModule } from '@nestjs/cqrs';
|
||||||
|
import { IndexItemCategoryManager } from './domain/usecases/managers/index-item-category.manager';
|
||||||
|
import { DeleteItemCategoryManager } from './domain/usecases/managers/delete-item-category.manager';
|
||||||
|
import { UpdateItemCategoryManager } from './domain/usecases/managers/update-item-category.manager';
|
||||||
|
import { ActiveItemCategoryManager } from './domain/usecases/managers/active-item-category.manager';
|
||||||
|
import { ConfirmItemCategoryManager } from './domain/usecases/managers/confirm-item-category.manager';
|
||||||
|
import { InactiveItemCategoryManager } from './domain/usecases/managers/inactive-item-category.manager';
|
||||||
|
import { DetailItemCategoryManager } from './domain/usecases/managers/detail-item-category.manager';
|
||||||
|
import { BatchDeleteItemCategoryManager } from './domain/usecases/managers/batch-delete-item-category.manager';
|
||||||
|
import { BatchActiveItemCategoryManager } from './domain/usecases/managers/batch-active-item-category.manager';
|
||||||
|
import { BatchConfirmItemCategoryManager } from './domain/usecases/managers/batch-confirm-item-category.manager';
|
||||||
|
import { BatchInactiveItemCategoryManager } from './domain/usecases/managers/batch-inactive-item-category.manager';
|
||||||
|
import { ItemCategoryModel } from './data/models/item-category.model';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
ConfigModule.forRoot(),
|
||||||
|
TypeOrmModule.forFeature([ItemCategoryModel], CONNECTION_NAME.DEFAULT),
|
||||||
|
CqrsModule,
|
||||||
|
],
|
||||||
|
controllers: [ItemCategoryDataController, ItemCategoryReadController],
|
||||||
|
providers: [
|
||||||
|
IndexItemCategoryManager,
|
||||||
|
DetailItemCategoryManager,
|
||||||
|
CreateItemCategoryManager,
|
||||||
|
DeleteItemCategoryManager,
|
||||||
|
UpdateItemCategoryManager,
|
||||||
|
ActiveItemCategoryManager,
|
||||||
|
ConfirmItemCategoryManager,
|
||||||
|
InactiveItemCategoryManager,
|
||||||
|
BatchDeleteItemCategoryManager,
|
||||||
|
BatchActiveItemCategoryManager,
|
||||||
|
BatchConfirmItemCategoryManager,
|
||||||
|
BatchInactiveItemCategoryManager,
|
||||||
|
|
||||||
|
ItemCategoryDataService,
|
||||||
|
ItemCategoryReadService,
|
||||||
|
|
||||||
|
ItemCategoryDataOrchestrator,
|
||||||
|
ItemCategoryReadOrchestrator,
|
||||||
|
],
|
||||||
|
})
|
||||||
|
export class ItemCategoryModule {}
|
Loading…
Reference in New Issue