diff --git a/src/app.module.ts b/src/app.module.ts index 3bd999d..42e866c 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -22,6 +22,8 @@ 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'; +import { VipCategoryModule } from './modules/transaction/vip-category/vip-category.module'; +import { VipCategoryModel } from './modules/transaction/vip-category/data/models/vip-category.model'; @Module({ imports: [ @@ -43,6 +45,7 @@ import { ConstantModule } from './modules/configuration/constant/constant.module LogModel, ErrorLogModel, ItemCategoryModel, + VipCategoryModel, ], synchronize: false, }), @@ -53,11 +56,16 @@ import { ConstantModule } from './modules/configuration/constant/constant.module CouchModule, LogModule, + // user TenantModule, UserModule, UserPrivilegeModule, + // Item ItemCategoryModule, + + // transaction + VipCategoryModule, ], controllers: [], providers: [ diff --git a/src/core/strings/constants/module.constants.ts b/src/core/strings/constants/module.constants.ts index 5a334a6..1f0a277 100644 --- a/src/core/strings/constants/module.constants.ts +++ b/src/core/strings/constants/module.constants.ts @@ -4,4 +4,5 @@ export enum MODULE_NAME { USER = 'users', USER_PRIVILEGE = 'user-privileges', USER_PRIVILEGE_CONFIGURATION = 'user-privilege-configurations', + VIP_CATEGORY = 'vip-categories', } diff --git a/src/core/strings/constants/table.constants.ts b/src/core/strings/constants/table.constants.ts index 7d28542..537f970 100644 --- a/src/core/strings/constants/table.constants.ts +++ b/src/core/strings/constants/table.constants.ts @@ -6,4 +6,5 @@ export enum TABLE_NAME { USER = 'users', USER_PRIVILEGE = 'user_privileges', USER_PRIVILEGE_CONFIGURATION = 'user_privilege_configurations', + VIP_CATEGORY = 'vip_categories', } diff --git a/src/database/migrations/1718070608814-vip-category.ts b/src/database/migrations/1718070608814-vip-category.ts new file mode 100644 index 0000000..af75d3f --- /dev/null +++ b/src/database/migrations/1718070608814-vip-category.ts @@ -0,0 +1,19 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class VipCategory1718070608814 implements MigrationInterface { + name = 'VipCategory1718070608814'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `CREATE TYPE "public"."vip_categories_status_enum" AS ENUM('active', 'cancel', 'confirmed', 'draft', 'expired', 'inactive', 'pending', 'refunded', 'rejected', 'settled', 'waiting')`, + ); + await queryRunner.query( + `CREATE TABLE "vip_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"."vip_categories_status_enum" NOT NULL DEFAULT 'draft', "name" character varying NOT NULL, CONSTRAINT "PK_b4873a565ca593e90eff71a99a3" PRIMARY KEY ("id"))`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE "vip_categories"`); + await queryRunner.query(`DROP TYPE "public"."vip_categories_status_enum"`); + } +} diff --git a/src/modules/transaction/vip-category/constants.ts b/src/modules/transaction/vip-category/constants.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/modules/transaction/vip-category/data/models/vip-category.model.ts b/src/modules/transaction/vip-category/data/models/vip-category.model.ts new file mode 100644 index 0000000..3fbff59 --- /dev/null +++ b/src/modules/transaction/vip-category/data/models/vip-category.model.ts @@ -0,0 +1,13 @@ +import { TABLE_NAME } from 'src/core/strings/constants/table.constants'; +import { VipCategoryEntity } from '../../domain/entities/vip-category.entity'; +import { Column, Entity } from 'typeorm'; +import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model'; + +@Entity(TABLE_NAME.VIP_CATEGORY) +export class VipCategoryModel + extends BaseStatusModel + implements VipCategoryEntity +{ + @Column('varchar', { name: 'name' }) + name: string; +} diff --git a/src/modules/transaction/vip-category/data/services/vip-category-data.service.ts b/src/modules/transaction/vip-category/data/services/vip-category-data.service.ts new file mode 100644 index 0000000..6413626 --- /dev/null +++ b/src/modules/transaction/vip-category/data/services/vip-category-data.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from '@nestjs/common'; +import { BaseDataService } from 'src/core/modules/data/service/base-data.service'; +import { VipCategoryEntity } from '../../domain/entities/vip-category.entity'; +import { InjectRepository } from '@nestjs/typeorm'; +import { VipCategoryModel } from '../models/vip-category.model'; +import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants'; +import { Repository } from 'typeorm'; + +@Injectable() +export class VipCategoryDataService extends BaseDataService { + constructor( + @InjectRepository(VipCategoryModel, CONNECTION_NAME.DEFAULT) + private repo: Repository, + ) { + super(repo); + } +} diff --git a/src/modules/transaction/vip-category/domain/entities/event/vip-category-change-status.event.ts b/src/modules/transaction/vip-category/domain/entities/event/vip-category-change-status.event.ts new file mode 100644 index 0000000..7d07d0e --- /dev/null +++ b/src/modules/transaction/vip-category/domain/entities/event/vip-category-change-status.event.ts @@ -0,0 +1,5 @@ +import { IEvent } from 'src/core/strings/constants/interface.constants'; + +export class VipCategoryChangeStatusEvent { + constructor(public readonly data: IEvent) {} +} diff --git a/src/modules/transaction/vip-category/domain/entities/event/vip-category-created.event.ts b/src/modules/transaction/vip-category/domain/entities/event/vip-category-created.event.ts new file mode 100644 index 0000000..eb63c3d --- /dev/null +++ b/src/modules/transaction/vip-category/domain/entities/event/vip-category-created.event.ts @@ -0,0 +1,5 @@ +import { IEvent } from 'src/core/strings/constants/interface.constants'; + +export class VipCategoryCreatedEvent { + constructor(public readonly data: IEvent) {} +} diff --git a/src/modules/transaction/vip-category/domain/entities/event/vip-category-deleted.event.ts b/src/modules/transaction/vip-category/domain/entities/event/vip-category-deleted.event.ts new file mode 100644 index 0000000..15e0122 --- /dev/null +++ b/src/modules/transaction/vip-category/domain/entities/event/vip-category-deleted.event.ts @@ -0,0 +1,5 @@ +import { IEvent } from 'src/core/strings/constants/interface.constants'; + +export class VipCategoryDeletedEvent { + constructor(public readonly data: IEvent) {} +} diff --git a/src/modules/transaction/vip-category/domain/entities/event/vip-category-updated.event.ts b/src/modules/transaction/vip-category/domain/entities/event/vip-category-updated.event.ts new file mode 100644 index 0000000..a7c2de8 --- /dev/null +++ b/src/modules/transaction/vip-category/domain/entities/event/vip-category-updated.event.ts @@ -0,0 +1,5 @@ +import { IEvent } from 'src/core/strings/constants/interface.constants'; + +export class VipCategoryUpdatedEvent { + constructor(public readonly data: IEvent) {} +} diff --git a/src/modules/transaction/vip-category/domain/entities/vip-category.entity.ts b/src/modules/transaction/vip-category/domain/entities/vip-category.entity.ts new file mode 100644 index 0000000..49af3a2 --- /dev/null +++ b/src/modules/transaction/vip-category/domain/entities/vip-category.entity.ts @@ -0,0 +1,5 @@ +import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.entity'; + +export interface VipCategoryEntity extends BaseStatusEntity { + name: string; +} diff --git a/src/modules/transaction/vip-category/domain/usecases/managers/active-vip-category.manager.ts b/src/modules/transaction/vip-category/domain/usecases/managers/active-vip-category.manager.ts new file mode 100644 index 0000000..9062c6e --- /dev/null +++ b/src/modules/transaction/vip-category/domain/usecases/managers/active-vip-category.manager.ts @@ -0,0 +1,45 @@ +import { Injectable } from '@nestjs/common'; +import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager'; +import { VipCategoryEntity } from '../../entities/vip-category.entity'; +import { + EventTopics, + validateRelations, +} from 'src/core/strings/constants/interface.constants'; +import { VipCategoryModel } from '../../../data/models/vip-category.model'; +import { VipCategoryChangeStatusEvent } from '../../entities/event/vip-category-change-status.event'; + +@Injectable() +export class ActiveVipCategoryManager extends BaseUpdateStatusManager { + getResult(): string { + return `Success active data ${this.result.name}`; + } + + async validateProcess(): Promise { + return; + } + + async beforeProcess(): Promise { + return; + } + + async afterProcess(): Promise { + return; + } + + get validateRelations(): validateRelations[] { + return []; + } + + get entityTarget(): any { + return VipCategoryModel; + } + + get eventTopics(): EventTopics[] { + return [ + { + topic: VipCategoryChangeStatusEvent, + data: this.data, + }, + ]; + } +} diff --git a/src/modules/transaction/vip-category/domain/usecases/managers/batch-active-vip-category.manager.ts b/src/modules/transaction/vip-category/domain/usecases/managers/batch-active-vip-category.manager.ts new file mode 100644 index 0000000..65c9660 --- /dev/null +++ b/src/modules/transaction/vip-category/domain/usecases/managers/batch-active-vip-category.manager.ts @@ -0,0 +1,45 @@ +import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager'; +import { VipCategoryEntity } from '../../entities/vip-category.entity'; +import { + EventTopics, + validateRelations, +} from 'src/core/strings/constants/interface.constants'; +import { VipCategoryModel } from '../../../data/models/vip-category.model'; +import { VipCategoryChangeStatusEvent } from '../../entities/event/vip-category-change-status.event'; +import { BatchResult } from 'src/core/response/domain/ok-response.interface'; +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class BatchActiveVipCategoryManager extends BaseBatchUpdateStatusManager { + validateData(data: VipCategoryEntity): Promise { + return; + } + + beforeProcess(): Promise { + return; + } + + afterProcess(): Promise { + return; + } + + get validateRelations(): validateRelations[] { + return []; + } + + get entityTarget(): any { + return VipCategoryModel; + } + + get eventTopics(): EventTopics[] { + return [ + { + topic: VipCategoryChangeStatusEvent, + }, + ]; + } + + getResult(): BatchResult { + return this.result; + } +} diff --git a/src/modules/transaction/vip-category/domain/usecases/managers/batch-confirm-vip-category.manager.ts b/src/modules/transaction/vip-category/domain/usecases/managers/batch-confirm-vip-category.manager.ts new file mode 100644 index 0000000..c00ee97 --- /dev/null +++ b/src/modules/transaction/vip-category/domain/usecases/managers/batch-confirm-vip-category.manager.ts @@ -0,0 +1,45 @@ +import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager'; +import { VipCategoryEntity } from '../../entities/vip-category.entity'; +import { + EventTopics, + validateRelations, +} from 'src/core/strings/constants/interface.constants'; +import { VipCategoryModel } from '../../../data/models/vip-category.model'; +import { VipCategoryChangeStatusEvent } from '../../entities/event/vip-category-change-status.event'; +import { BatchResult } from 'src/core/response/domain/ok-response.interface'; +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class BatchConfirmVipCategoryManager extends BaseBatchUpdateStatusManager { + validateData(data: VipCategoryEntity): Promise { + return; + } + + beforeProcess(): Promise { + return; + } + + afterProcess(): Promise { + return; + } + + get validateRelations(): validateRelations[] { + return []; + } + + get entityTarget(): any { + return VipCategoryModel; + } + + get eventTopics(): EventTopics[] { + return [ + { + topic: VipCategoryChangeStatusEvent, + }, + ]; + } + + getResult(): BatchResult { + return this.result; + } +} diff --git a/src/modules/transaction/vip-category/domain/usecases/managers/batch-delete-vip-category.manager.ts b/src/modules/transaction/vip-category/domain/usecases/managers/batch-delete-vip-category.manager.ts new file mode 100644 index 0000000..4ef0343 --- /dev/null +++ b/src/modules/transaction/vip-category/domain/usecases/managers/batch-delete-vip-category.manager.ts @@ -0,0 +1,45 @@ +import { BaseBatchDeleteManager } from 'src/core/modules/domain/usecase/managers/base-batch-delete.manager'; +import { VipCategoryEntity } from '../../entities/vip-category.entity'; +import { + EventTopics, + validateRelations, +} from 'src/core/strings/constants/interface.constants'; +import { VipCategoryModel } from '../../../data/models/vip-category.model'; +import { VipCategoryDeletedEvent } from '../../entities/event/vip-category-deleted.event'; +import { BatchResult } from 'src/core/response/domain/ok-response.interface'; +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class BatchDeleteVipCategoryManager extends BaseBatchDeleteManager { + async beforeProcess(): Promise { + return; + } + + async validateData(data: VipCategoryEntity): Promise { + return; + } + + async afterProcess(): Promise { + return; + } + + get validateRelations(): validateRelations[] { + return []; + } + + get entityTarget(): any { + return VipCategoryModel; + } + + get eventTopics(): EventTopics[] { + return [ + { + topic: VipCategoryDeletedEvent, + }, + ]; + } + + getResult(): BatchResult { + return this.result; + } +} diff --git a/src/modules/transaction/vip-category/domain/usecases/managers/batch-inactive-vip-category.manager.ts b/src/modules/transaction/vip-category/domain/usecases/managers/batch-inactive-vip-category.manager.ts new file mode 100644 index 0000000..5bfa348 --- /dev/null +++ b/src/modules/transaction/vip-category/domain/usecases/managers/batch-inactive-vip-category.manager.ts @@ -0,0 +1,45 @@ +import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager'; +import { VipCategoryEntity } from '../../entities/vip-category.entity'; +import { + EventTopics, + validateRelations, +} from 'src/core/strings/constants/interface.constants'; +import { VipCategoryModel } from '../../../data/models/vip-category.model'; +import { VipCategoryChangeStatusEvent } from '../../entities/event/vip-category-change-status.event'; +import { BatchResult } from 'src/core/response/domain/ok-response.interface'; +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class BatchInactiveVipCategoryManager extends BaseBatchUpdateStatusManager { + validateData(data: VipCategoryEntity): Promise { + return; + } + + beforeProcess(): Promise { + return; + } + + afterProcess(): Promise { + return; + } + + get validateRelations(): validateRelations[] { + return []; + } + + get entityTarget(): any { + return VipCategoryModel; + } + + get eventTopics(): EventTopics[] { + return [ + { + topic: VipCategoryChangeStatusEvent, + }, + ]; + } + + getResult(): BatchResult { + return this.result; + } +} diff --git a/src/modules/transaction/vip-category/domain/usecases/managers/confirm-vip-category.manager.ts b/src/modules/transaction/vip-category/domain/usecases/managers/confirm-vip-category.manager.ts new file mode 100644 index 0000000..be603f0 --- /dev/null +++ b/src/modules/transaction/vip-category/domain/usecases/managers/confirm-vip-category.manager.ts @@ -0,0 +1,45 @@ +import { Injectable } from '@nestjs/common'; +import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager'; +import { VipCategoryEntity } from '../../entities/vip-category.entity'; +import { + EventTopics, + validateRelations, +} from 'src/core/strings/constants/interface.constants'; +import { VipCategoryModel } from '../../../data/models/vip-category.model'; +import { VipCategoryChangeStatusEvent } from '../../entities/event/vip-category-change-status.event'; + +@Injectable() +export class ConfirmVipCategoryManager extends BaseUpdateStatusManager { + getResult(): string { + return `Success active data ${this.result.name}`; + } + + async validateProcess(): Promise { + return; + } + + async beforeProcess(): Promise { + return; + } + + async afterProcess(): Promise { + return; + } + + get validateRelations(): validateRelations[] { + return []; + } + + get entityTarget(): any { + return VipCategoryModel; + } + + get eventTopics(): EventTopics[] { + return [ + { + topic: VipCategoryChangeStatusEvent, + data: this.data, + }, + ]; + } +} diff --git a/src/modules/transaction/vip-category/domain/usecases/managers/create-vip-category.manager.ts b/src/modules/transaction/vip-category/domain/usecases/managers/create-vip-category.manager.ts new file mode 100644 index 0000000..d2f77ac --- /dev/null +++ b/src/modules/transaction/vip-category/domain/usecases/managers/create-vip-category.manager.ts @@ -0,0 +1,44 @@ +import { Injectable } from '@nestjs/common'; +import { + EventTopics, + columnUniques, + validateRelations, +} from 'src/core/strings/constants/interface.constants'; +import { VipCategoryEntity } from '../../entities/vip-category.entity'; +import { VipCategoryModel } from '../../../data/models/vip-category.model'; +import { BaseCreateManager } from 'src/core/modules/domain/usecase/managers/base-create.manager'; +import { VipCategoryCreatedEvent } from '../../entities/event/vip-category-created.event'; + +@Injectable() +export class CreateVipCategoryManager extends BaseCreateManager { + async beforeProcess(): Promise { + return; + } + + async afterProcess(): Promise { + return; + } + + async generateConfig(): Promise {} + + get validateRelations(): validateRelations[] { + return []; + } + + get uniqueColumns(): columnUniques[] { + return [{ column: 'name' }]; + } + + get eventTopics(): EventTopics[] { + return [ + { + topic: VipCategoryCreatedEvent, + data: this.data, + }, + ]; + } + + get entityTarget(): any { + return VipCategoryModel; + } +} diff --git a/src/modules/transaction/vip-category/domain/usecases/managers/delete-vip-category.manager.ts b/src/modules/transaction/vip-category/domain/usecases/managers/delete-vip-category.manager.ts new file mode 100644 index 0000000..1844f04 --- /dev/null +++ b/src/modules/transaction/vip-category/domain/usecases/managers/delete-vip-category.manager.ts @@ -0,0 +1,45 @@ +import { Injectable } from '@nestjs/common'; +import { BaseDeleteManager } from 'src/core/modules/domain/usecase/managers/base-delete.manager'; +import { VipCategoryEntity } from '../../entities/vip-category.entity'; +import { + EventTopics, + validateRelations, +} from 'src/core/strings/constants/interface.constants'; +import { VipCategoryModel } from '../../../data/models/vip-category.model'; +import { VipCategoryDeletedEvent } from '../../entities/event/vip-category-deleted.event'; + +@Injectable() +export class DeleteVipCategoryManager extends BaseDeleteManager { + getResult(): string { + return `Success`; + } + + async validateProcess(): Promise { + return; + } + + async beforeProcess(): Promise { + return; + } + + async afterProcess(): Promise { + return; + } + + get validateRelations(): validateRelations[] { + return []; + } + + get entityTarget(): any { + return VipCategoryModel; + } + + get eventTopics(): EventTopics[] { + return [ + { + topic: VipCategoryDeletedEvent, + data: this.data, + }, + ]; + } +} diff --git a/src/modules/transaction/vip-category/domain/usecases/managers/inactive-vip-category.manager.ts b/src/modules/transaction/vip-category/domain/usecases/managers/inactive-vip-category.manager.ts new file mode 100644 index 0000000..0c6f582 --- /dev/null +++ b/src/modules/transaction/vip-category/domain/usecases/managers/inactive-vip-category.manager.ts @@ -0,0 +1,45 @@ +import { Injectable } from '@nestjs/common'; +import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager'; +import { VipCategoryEntity } from '../../entities/vip-category.entity'; +import { + EventTopics, + validateRelations, +} from 'src/core/strings/constants/interface.constants'; +import { VipCategoryModel } from '../../../data/models/vip-category.model'; +import { VipCategoryChangeStatusEvent } from '../../entities/event/vip-category-change-status.event'; + +@Injectable() +export class InactiveVipCategoryManager extends BaseUpdateStatusManager { + getResult(): string { + return `Success inactive data ${this.result.name}`; + } + + async validateProcess(): Promise { + return; + } + + async beforeProcess(): Promise { + return; + } + + async afterProcess(): Promise { + return; + } + + get validateRelations(): validateRelations[] { + return []; + } + + get entityTarget(): any { + return VipCategoryModel; + } + + get eventTopics(): EventTopics[] { + return [ + { + topic: VipCategoryChangeStatusEvent, + data: this.data, + }, + ]; + } +} diff --git a/src/modules/transaction/vip-category/domain/usecases/managers/update-vip-category.manager.ts b/src/modules/transaction/vip-category/domain/usecases/managers/update-vip-category.manager.ts new file mode 100644 index 0000000..fdeac53 --- /dev/null +++ b/src/modules/transaction/vip-category/domain/usecases/managers/update-vip-category.manager.ts @@ -0,0 +1,46 @@ +import { Injectable } from '@nestjs/common'; +import { BaseUpdateManager } from 'src/core/modules/domain/usecase/managers/base-update.manager'; +import { VipCategoryEntity } from '../../entities/vip-category.entity'; +import { VipCategoryModel } from '../../../data/models/vip-category.model'; +import { VipCategoryUpdatedEvent } from '../../entities/event/vip-category-updated.event'; +import { + EventTopics, + columnUniques, + validateRelations, +} from 'src/core/strings/constants/interface.constants'; + +@Injectable() +export class UpdateVipCategoryManager extends BaseUpdateManager { + async validateProcess(): Promise { + return; + } + + async beforeProcess(): Promise { + return; + } + + async afterProcess(): Promise { + return; + } + + get validateRelations(): validateRelations[] { + return []; + } + + get uniqueColumns(): columnUniques[] { + return [{ column: 'name' }]; + } + + get entityTarget(): any { + return VipCategoryModel; + } + + get eventTopics(): EventTopics[] { + return [ + { + topic: VipCategoryUpdatedEvent, + data: this.data, + }, + ]; + } +} diff --git a/src/modules/transaction/vip-category/domain/usecases/vip-category-data.orchestrator.ts b/src/modules/transaction/vip-category/domain/usecases/vip-category-data.orchestrator.ts new file mode 100644 index 0000000..92b6c8a --- /dev/null +++ b/src/modules/transaction/vip-category/domain/usecases/vip-category-data.orchestrator.ts @@ -0,0 +1,119 @@ +import { Injectable } from '@nestjs/common'; +import { CreateVipCategoryManager } from './managers/create-vip-category.manager'; +import { VipCategoryDataService } from '../../data/services/vip-category-data.service'; +import { VipCategoryEntity } from '../entities/vip-category.entity'; +import { DeleteVipCategoryManager } from './managers/delete-vip-category.manager'; +import { UpdateVipCategoryManager } from './managers/update-vip-category.manager'; +import { BaseDataTransactionOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-data-transaction.orchestrator'; +import { ActiveVipCategoryManager } from './managers/active-vip-category.manager'; +import { InactiveVipCategoryManager } from './managers/inactive-vip-category.manager'; +import { ConfirmVipCategoryManager } from './managers/confirm-vip-category.manager'; +import { STATUS } from 'src/core/strings/constants/base.constants'; +import { BatchResult } from 'src/core/response/domain/ok-response.interface'; +import { BatchConfirmVipCategoryManager } from './managers/batch-confirm-vip-category.manager'; +import { BatchInactiveVipCategoryManager } from './managers/batch-inactive-vip-category.manager'; +import { BatchActiveVipCategoryManager } from './managers/batch-active-vip-category.manager'; +import { BatchDeleteVipCategoryManager } from './managers/batch-delete-vip-category.manager'; +import { TABLE_NAME } from 'src/core/strings/constants/table.constants'; + +@Injectable() +export class VipCategoryDataOrchestrator extends BaseDataTransactionOrchestrator { + constructor( + private createManager: CreateVipCategoryManager, + private updateManager: UpdateVipCategoryManager, + private deleteManager: DeleteVipCategoryManager, + private activeManager: ActiveVipCategoryManager, + private confirmManager: ConfirmVipCategoryManager, + private inactiveManager: InactiveVipCategoryManager, + private batchDeleteManager: BatchDeleteVipCategoryManager, + private batchActiveManager: BatchActiveVipCategoryManager, + private batchConfirmManager: BatchConfirmVipCategoryManager, + private batchInactiveManager: BatchInactiveVipCategoryManager, + private serviceData: VipCategoryDataService, + ) { + super(); + } + + async create(data): Promise { + this.createManager.setData(data); + this.createManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY); + await this.createManager.execute(); + await this.createManager.generateConfig(); + return this.createManager.getResult(); + } + + async update(dataId, data): Promise { + this.updateManager.setData(dataId, data); + this.updateManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY); + await this.updateManager.execute(); + return this.updateManager.getResult(); + } + + async delete(dataId): Promise { + this.deleteManager.setData(dataId); + this.deleteManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY); + await this.deleteManager.execute(); + return this.deleteManager.getResult(); + } + + async batchDelete(dataIds: string[]): Promise { + this.batchDeleteManager.setData(dataIds); + this.batchDeleteManager.setService( + this.serviceData, + TABLE_NAME.VIP_CATEGORY, + ); + await this.batchDeleteManager.execute(); + return this.batchDeleteManager.getResult(); + } + + async active(dataId): Promise { + this.activeManager.setData(dataId, STATUS.ACTIVE); + this.activeManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY); + await this.activeManager.execute(); + return this.activeManager.getResult(); + } + + async batchActive(dataIds: string[]): Promise { + this.batchActiveManager.setData(dataIds, STATUS.ACTIVE); + this.batchActiveManager.setService( + this.serviceData, + TABLE_NAME.VIP_CATEGORY, + ); + await this.batchActiveManager.execute(); + return this.batchActiveManager.getResult(); + } + + async confirm(dataId): Promise { + this.confirmManager.setData(dataId, STATUS.ACTIVE); + this.confirmManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY); + await this.confirmManager.execute(); + return this.confirmManager.getResult(); + } + + async batchConfirm(dataIds: string[]): Promise { + this.batchConfirmManager.setData(dataIds, STATUS.ACTIVE); + this.batchConfirmManager.setService( + this.serviceData, + TABLE_NAME.VIP_CATEGORY, + ); + await this.batchConfirmManager.execute(); + return this.batchConfirmManager.getResult(); + } + + async inactive(dataId): Promise { + this.inactiveManager.setData(dataId, STATUS.INACTIVE); + this.inactiveManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY); + await this.inactiveManager.execute(); + return this.inactiveManager.getResult(); + } + + async batchInactive(dataIds: string[]): Promise { + this.batchInactiveManager.setData(dataIds, STATUS.INACTIVE); + this.batchInactiveManager.setService( + this.serviceData, + TABLE_NAME.VIP_CATEGORY, + ); + await this.batchInactiveManager.execute(); + return this.batchInactiveManager.getResult(); + } +} diff --git a/src/modules/transaction/vip-category/index.ts b/src/modules/transaction/vip-category/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/modules/transaction/vip-category/infrastructure/dto/vip-category.dto.ts b/src/modules/transaction/vip-category/infrastructure/dto/vip-category.dto.ts new file mode 100644 index 0000000..5173949 --- /dev/null +++ b/src/modules/transaction/vip-category/infrastructure/dto/vip-category.dto.ts @@ -0,0 +1,15 @@ +import { BaseStatusDto } from 'src/core/modules/infrastructure/dto/base-status.dto'; +import { VipCategoryEntity } from '../../domain/entities/vip-category.entity'; +import { ApiProperty } from '@nestjs/swagger'; +import { IsString } from 'class-validator'; + +export class VipCategoryDto extends BaseStatusDto implements VipCategoryEntity { + @ApiProperty({ + name: 'name', + type: String, + required: true, + example: 'Influencer', + }) + @IsString() + name: string; +} diff --git a/src/modules/transaction/vip-category/infrastructure/vip-category-data.controller.ts b/src/modules/transaction/vip-category/infrastructure/vip-category-data.controller.ts new file mode 100644 index 0000000..e630a15 --- /dev/null +++ b/src/modules/transaction/vip-category/infrastructure/vip-category-data.controller.ts @@ -0,0 +1,78 @@ +import { + Body, + Controller, + Delete, + Param, + Patch, + Post, + Put, +} from '@nestjs/common'; +import { VipCategoryDataOrchestrator } from '../domain/usecases/vip-category-data.orchestrator'; +import { VipCategoryDto } from './dto/vip-category.dto'; +import { MODULE_NAME } from 'src/core/strings/constants/module.constants'; +import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; +import { VipCategoryEntity } from '../domain/entities/vip-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.VIP_CATEGORY.split('-').join(' ')} - data`) +@Controller(MODULE_NAME.VIP_CATEGORY) +@Public(false) +@ApiBearerAuth('JWT') +export class VipCategoryDataController { + constructor(private orchestrator: VipCategoryDataOrchestrator) {} + + @Post() + async create(@Body() data: VipCategoryDto): Promise { + return await this.orchestrator.create(data); + } + + @Put('/batch-delete') + async batchDeleted(@Body() body: BatchIdsDto): Promise { + return await this.orchestrator.batchDelete(body.ids); + } + + @Patch(':id/active') + async active(@Param('id') dataId: string): Promise { + return await this.orchestrator.active(dataId); + } + + @Put('/batch-active') + async batchActive(@Body() body: BatchIdsDto): Promise { + return await this.orchestrator.batchActive(body.ids); + } + + @Patch(':id/confirm') + async confirm(@Param('id') dataId: string): Promise { + return await this.orchestrator.confirm(dataId); + } + + @Put('/batch-confirm') + async batchConfirm(@Body() body: BatchIdsDto): Promise { + return await this.orchestrator.batchConfirm(body.ids); + } + + @Patch(':id/inactive') + async inactive(@Param('id') dataId: string): Promise { + return await this.orchestrator.inactive(dataId); + } + + @Put('/batch-inactive') + async batchInactive(@Body() body: BatchIdsDto): Promise { + return await this.orchestrator.batchInactive(body.ids); + } + + @Put(':id') + async update( + @Param('id') dataId: string, + @Body() data: VipCategoryDto, + ): Promise { + return await this.orchestrator.update(dataId, data); + } + + @Delete(':id') + async delete(@Param('id') dataId: string): Promise { + return await this.orchestrator.delete(dataId); + } +} diff --git a/src/modules/transaction/vip-category/vip-category.module.ts b/src/modules/transaction/vip-category/vip-category.module.ts new file mode 100644 index 0000000..83eaf9f --- /dev/null +++ b/src/modules/transaction/vip-category/vip-category.module.ts @@ -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 { VipCategoryDataService } from './data/services/vip-category-data.service'; +import { VipCategoryReadService } from './data/services/vip-category-read.service'; +import { VipCategoryReadController } from './infrastructure/vip-category-read.controller'; +import { VipCategoryReadOrchestrator } from './domain/usecases/vip-category-read.orchestrator'; +import { VipCategoryDataController } from './infrastructure/vip-category-data.controller'; +import { VipCategoryDataOrchestrator } from './domain/usecases/vip-category-data.orchestrator'; +import { CreateVipCategoryManager } from './domain/usecases/managers/create-vip-category.manager'; +import { CqrsModule } from '@nestjs/cqrs'; +import { IndexVipCategoryManager } from './domain/usecases/managers/index-vip-category.manager'; +import { DeleteVipCategoryManager } from './domain/usecases/managers/delete-vip-category.manager'; +import { UpdateVipCategoryManager } from './domain/usecases/managers/update-vip-category.manager'; +import { ActiveVipCategoryManager } from './domain/usecases/managers/active-vip-category.manager'; +import { ConfirmVipCategoryManager } from './domain/usecases/managers/confirm-vip-category.manager'; +import { InactiveVipCategoryManager } from './domain/usecases/managers/inactive-vip-category.manager'; +import { DetailVipCategoryManager } from './domain/usecases/managers/detail-vip-category.manager'; +import { BatchDeleteVipCategoryManager } from './domain/usecases/managers/batch-delete-vip-category.manager'; +import { BatchActiveVipCategoryManager } from './domain/usecases/managers/batch-active-vip-category.manager'; +import { BatchConfirmVipCategoryManager } from './domain/usecases/managers/batch-confirm-vip-category.manager'; +import { BatchInactiveVipCategoryManager } from './domain/usecases/managers/batch-inactive-vip-category.manager'; +import { VipCategoryModel } from './data/models/vip-category.model'; + +@Module({ + imports: [ + ConfigModule.forRoot(), + TypeOrmModule.forFeature([VipCategoryModel], CONNECTION_NAME.DEFAULT), + CqrsModule, + ], + controllers: [VipCategoryDataController, VipCategoryReadController], + providers: [ + IndexVipCategoryManager, + DetailVipCategoryManager, + CreateVipCategoryManager, + DeleteVipCategoryManager, + UpdateVipCategoryManager, + ActiveVipCategoryManager, + ConfirmVipCategoryManager, + InactiveVipCategoryManager, + BatchDeleteVipCategoryManager, + BatchActiveVipCategoryManager, + BatchConfirmVipCategoryManager, + BatchInactiveVipCategoryManager, + + VipCategoryDataService, + VipCategoryReadService, + + VipCategoryDataOrchestrator, + VipCategoryReadOrchestrator, + ], +}) +export class VipCategoryModule {}