From d9d22779f01fd0c7ce0941dd39e7a6f73f3289c5 Mon Sep 17 00:00:00 2001 From: ashar Date: Wed, 12 Jun 2024 11:21:22 +0700 Subject: [PATCH] feat(SPG-487) REST API CU Profit Share Formula --- src/app.module.ts | 2 + .../profit-share-formula/constants.ts | 0 .../profit-share-formula-updated.event.ts} | 2 +- .../detail-profit-share-formula.manager.ts | 43 +++++++++++++++++ .../update-profit-share-formula.manager.ts | 46 +++++++++++++++++++ .../profit-share-formula-data.orchestrator.ts | 27 +++++++++++ .../profit-share-formula-read.orchestrator.ts | 20 ++++++++ .../transaction/profit-share-formula/index.ts | 0 .../profit-share-formula-data.controller.ts | 21 +++++++++ .../profit-share-formula-read.controller.ts | 18 ++++++++ .../profit-share-formula.module.ts | 32 +++++++++++++ .../sales-price-formula-deleted.event.ts | 5 -- .../sales-price-formula.module.ts | 4 +- 13 files changed, 213 insertions(+), 7 deletions(-) create mode 100644 src/modules/transaction/profit-share-formula/constants.ts rename src/modules/transaction/{sales-price-formula/domain/entities/event/sales-price-formula-created.event.ts => profit-share-formula/domain/entities/event/profit-share-formula-updated.event.ts} (72%) create mode 100644 src/modules/transaction/profit-share-formula/domain/usecases/managers/detail-profit-share-formula.manager.ts create mode 100644 src/modules/transaction/profit-share-formula/domain/usecases/managers/update-profit-share-formula.manager.ts create mode 100644 src/modules/transaction/profit-share-formula/domain/usecases/profit-share-formula-data.orchestrator.ts create mode 100644 src/modules/transaction/profit-share-formula/domain/usecases/profit-share-formula-read.orchestrator.ts create mode 100644 src/modules/transaction/profit-share-formula/index.ts create mode 100644 src/modules/transaction/profit-share-formula/infrastructure/profit-share-formula-data.controller.ts create mode 100644 src/modules/transaction/profit-share-formula/infrastructure/profit-share-formula-read.controller.ts create mode 100644 src/modules/transaction/profit-share-formula/profit-share-formula.module.ts delete mode 100644 src/modules/transaction/sales-price-formula/domain/entities/event/sales-price-formula-deleted.event.ts diff --git a/src/app.module.ts b/src/app.module.ts index 61a1a96..94f1eb6 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -34,6 +34,7 @@ import { TaxModule } from './modules/transaction/tax/tax.module'; import { TaxModel } from './modules/transaction/tax/data/models/tax.model'; import { SalesPriceFormulaModule } from './modules/transaction/sales-price-formula/sales-price-formula.module'; import { SalesPriceFormulaModel } from './modules/transaction/sales-price-formula/data/models/sales-price-formula.model'; +import { ProfitShareFormulaModule } from './modules/transaction/profit-share-formula/profit-share-formula.module'; @Module({ imports: [ @@ -81,6 +82,7 @@ import { SalesPriceFormulaModel } from './modules/transaction/sales-price-formul ItemModule, // transaction + ProfitShareFormulaModule, SalesPriceFormulaModule, TaxModule, VipCategoryModule, diff --git a/src/modules/transaction/profit-share-formula/constants.ts b/src/modules/transaction/profit-share-formula/constants.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/modules/transaction/sales-price-formula/domain/entities/event/sales-price-formula-created.event.ts b/src/modules/transaction/profit-share-formula/domain/entities/event/profit-share-formula-updated.event.ts similarity index 72% rename from src/modules/transaction/sales-price-formula/domain/entities/event/sales-price-formula-created.event.ts rename to src/modules/transaction/profit-share-formula/domain/entities/event/profit-share-formula-updated.event.ts index e5823da..22773e4 100644 --- a/src/modules/transaction/sales-price-formula/domain/entities/event/sales-price-formula-created.event.ts +++ b/src/modules/transaction/profit-share-formula/domain/entities/event/profit-share-formula-updated.event.ts @@ -1,5 +1,5 @@ import { IEvent } from 'src/core/strings/constants/interface.constants'; -export class SalesPriceFormulaCreatedEvent { +export class ProfitShareFormulaUpdatedEvent { constructor(public readonly data: IEvent) {} } diff --git a/src/modules/transaction/profit-share-formula/domain/usecases/managers/detail-profit-share-formula.manager.ts b/src/modules/transaction/profit-share-formula/domain/usecases/managers/detail-profit-share-formula.manager.ts new file mode 100644 index 0000000..8ffbae3 --- /dev/null +++ b/src/modules/transaction/profit-share-formula/domain/usecases/managers/detail-profit-share-formula.manager.ts @@ -0,0 +1,43 @@ +import { Injectable } from '@nestjs/common'; +import { BaseDetailManager } from 'src/core/modules/domain/usecase/managers/base-detail.manager'; +import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity'; +import { FormulaType } from 'src/modules/transaction/sales-price-formula/constants'; +import { SalesPriceFormulaEntity } from 'src/modules/transaction/sales-price-formula/domain/entities/sales-price-formula.entity'; + +@Injectable() +export class DetailProfitShareFormulaManager extends BaseDetailManager { + async prepareData(): Promise { + return; + } + + async beforeProcess(): Promise { + return; + } + + async afterProcess(): Promise { + return; + } + + get relations(): RelationParam { + return { + // relation only join (for query purpose) + joinRelations: [], + + // relation join and select (relasi yang ingin ditampilkan), + selectRelations: [], + + // relation yang hanya ingin dihitung (akan return number) + countRelations: [], + }; + } + + get selects(): string[] { + return []; + } + + get setFindProperties(): any { + return { + type: FormulaType.PROFIT_SHARE, + }; + } +} diff --git a/src/modules/transaction/profit-share-formula/domain/usecases/managers/update-profit-share-formula.manager.ts b/src/modules/transaction/profit-share-formula/domain/usecases/managers/update-profit-share-formula.manager.ts new file mode 100644 index 0000000..59139db --- /dev/null +++ b/src/modules/transaction/profit-share-formula/domain/usecases/managers/update-profit-share-formula.manager.ts @@ -0,0 +1,46 @@ +import { Injectable } from '@nestjs/common'; +import { BaseUpdateManager } from 'src/core/modules/domain/usecase/managers/base-update.manager'; +import { + EventTopics, + columnUniques, + validateRelations, +} from 'src/core/strings/constants/interface.constants'; +import { SalesPriceFormulaModel } from 'src/modules/transaction/sales-price-formula/data/models/sales-price-formula.model'; +import { ProfitShareFormulaUpdatedEvent } from '../../entities/event/profit-share-formula-updated.event'; +import { SalesPriceFormulaEntity } from 'src/modules/transaction/sales-price-formula/domain/entities/sales-price-formula.entity'; + +@Injectable() +export class UpdateProfitShareFormulaManager extends BaseUpdateManager { + async validateProcess(): Promise { + return; + } + + async beforeProcess(): Promise { + return; + } + + async afterProcess(): Promise { + return; + } + + get validateRelations(): validateRelations[] { + return []; + } + + get uniqueColumns(): columnUniques[] { + return []; + } + + get entityTarget(): any { + return SalesPriceFormulaModel; + } + + get eventTopics(): EventTopics[] { + return [ + { + topic: ProfitShareFormulaUpdatedEvent, + data: this.data, + }, + ]; + } +} diff --git a/src/modules/transaction/profit-share-formula/domain/usecases/profit-share-formula-data.orchestrator.ts b/src/modules/transaction/profit-share-formula/domain/usecases/profit-share-formula-data.orchestrator.ts new file mode 100644 index 0000000..2b3806f --- /dev/null +++ b/src/modules/transaction/profit-share-formula/domain/usecases/profit-share-formula-data.orchestrator.ts @@ -0,0 +1,27 @@ +import { Injectable } from '@nestjs/common'; +import { UpdateProfitShareFormulaManager } from './managers/update-profit-share-formula.manager'; +import { TABLE_NAME } from 'src/core/strings/constants/table.constants'; +import { SalesPriceFormulaDataService } from 'src/modules/transaction/sales-price-formula/data/services/sales-price-formula-data.service'; +import { FormulaType } from 'src/modules/transaction/sales-price-formula/constants'; +import { SalesPriceFormulaEntity } from 'src/modules/transaction/sales-price-formula/domain/entities/sales-price-formula.entity'; + +@Injectable() +export class ProfitShareFormulaDataOrchestrator { + constructor( + private updateManager: UpdateProfitShareFormulaManager, + private serviceData: SalesPriceFormulaDataService, + ) {} + + async update(data): Promise { + const formula = await this.serviceData.getOneByOptions({ + where: { + type: FormulaType.PROFIT_SHARE, + }, + }); + + this.updateManager.setData(formula.id, data); + this.updateManager.setService(this.serviceData, TABLE_NAME.PRICE_FORMULA); + await this.updateManager.execute(); + return this.updateManager.getResult(); + } +} diff --git a/src/modules/transaction/profit-share-formula/domain/usecases/profit-share-formula-read.orchestrator.ts b/src/modules/transaction/profit-share-formula/domain/usecases/profit-share-formula-read.orchestrator.ts new file mode 100644 index 0000000..ef86f67 --- /dev/null +++ b/src/modules/transaction/profit-share-formula/domain/usecases/profit-share-formula-read.orchestrator.ts @@ -0,0 +1,20 @@ +import { Injectable } from '@nestjs/common'; +import { DetailProfitShareFormulaManager } from './managers/detail-profit-share-formula.manager'; +import { TABLE_NAME } from 'src/core/strings/constants/table.constants'; +import { SalesPriceFormulaReadService } from 'src/modules/transaction/sales-price-formula/data/services/sales-price-formula-read.service'; +import { SalesPriceFormulaEntity } from 'src/modules/transaction/sales-price-formula/domain/entities/sales-price-formula.entity'; + +@Injectable() +export class ProfitShareFormulaReadOrchestrator { + constructor( + private detailManager: DetailProfitShareFormulaManager, + private serviceData: SalesPriceFormulaReadService, + ) {} + + async detail(): Promise { + this.detailManager.setData(''); + this.detailManager.setService(this.serviceData, TABLE_NAME.PRICE_FORMULA); + await this.detailManager.execute(); + return this.detailManager.getResult(); + } +} diff --git a/src/modules/transaction/profit-share-formula/index.ts b/src/modules/transaction/profit-share-formula/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/modules/transaction/profit-share-formula/infrastructure/profit-share-formula-data.controller.ts b/src/modules/transaction/profit-share-formula/infrastructure/profit-share-formula-data.controller.ts new file mode 100644 index 0000000..068e127 --- /dev/null +++ b/src/modules/transaction/profit-share-formula/infrastructure/profit-share-formula-data.controller.ts @@ -0,0 +1,21 @@ +import { Body, Controller, Post } from '@nestjs/common'; +import { ProfitShareFormulaDataOrchestrator } from '../domain/usecases/profit-share-formula-data.orchestrator'; +import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; +import { Public } from 'src/core/guards'; +import { SalesPriceFormulaEntity } from '../../sales-price-formula/domain/entities/sales-price-formula.entity'; +import { SalesPriceFormulaDto } from '../../sales-price-formula/infrastructure/dto/sales-price-formula.dto'; + +@ApiTags(`profit share formula - data`) +@Controller('profit-share-formula') +@Public(false) +@ApiBearerAuth('JWT') +export class ProfitShareFormulaDataController { + constructor(private orchestrator: ProfitShareFormulaDataOrchestrator) {} + + @Post() + async create( + @Body() data: SalesPriceFormulaDto, + ): Promise { + return await this.orchestrator.update(data); + } +} diff --git a/src/modules/transaction/profit-share-formula/infrastructure/profit-share-formula-read.controller.ts b/src/modules/transaction/profit-share-formula/infrastructure/profit-share-formula-read.controller.ts new file mode 100644 index 0000000..ce43f29 --- /dev/null +++ b/src/modules/transaction/profit-share-formula/infrastructure/profit-share-formula-read.controller.ts @@ -0,0 +1,18 @@ +import { Controller, Get, Param } from '@nestjs/common'; +import { ProfitShareFormulaReadOrchestrator } from '../domain/usecases/profit-share-formula-read.orchestrator'; +import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; +import { Public } from 'src/core/guards'; +import { SalesPriceFormulaEntity } from '../../sales-price-formula/domain/entities/sales-price-formula.entity'; + +@ApiTags(`profit share formula - read`) +@Controller('profit-share-formula') +@Public(false) +@ApiBearerAuth('JWT') +export class ProfitShareFormulaReadController { + constructor(private orchestrator: ProfitShareFormulaReadOrchestrator) {} + + @Get() + async detail(): Promise { + return await this.orchestrator.detail(); + } +} diff --git a/src/modules/transaction/profit-share-formula/profit-share-formula.module.ts b/src/modules/transaction/profit-share-formula/profit-share-formula.module.ts new file mode 100644 index 0000000..ea4105b --- /dev/null +++ b/src/modules/transaction/profit-share-formula/profit-share-formula.module.ts @@ -0,0 +1,32 @@ +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 { ProfitShareFormulaReadController } from './infrastructure/profit-share-formula-read.controller'; +import { ProfitShareFormulaReadOrchestrator } from './domain/usecases/profit-share-formula-read.orchestrator'; +import { ProfitShareFormulaDataController } from './infrastructure/profit-share-formula-data.controller'; +import { ProfitShareFormulaDataOrchestrator } from './domain/usecases/profit-share-formula-data.orchestrator'; +import { CqrsModule } from '@nestjs/cqrs'; +import { UpdateProfitShareFormulaManager } from './domain/usecases/managers/update-profit-share-formula.manager'; +import { DetailProfitShareFormulaManager } from './domain/usecases/managers/detail-profit-share-formula.manager'; +import { SalesPriceFormulaModel } from '../sales-price-formula/data/models/sales-price-formula.model'; + +@Module({ + imports: [ + ConfigModule.forRoot(), + TypeOrmModule.forFeature([SalesPriceFormulaModel], CONNECTION_NAME.DEFAULT), + CqrsModule, + ], + controllers: [ + ProfitShareFormulaDataController, + ProfitShareFormulaReadController, + ], + providers: [ + DetailProfitShareFormulaManager, + UpdateProfitShareFormulaManager, + + ProfitShareFormulaDataOrchestrator, + ProfitShareFormulaReadOrchestrator, + ], +}) +export class ProfitShareFormulaModule {} diff --git a/src/modules/transaction/sales-price-formula/domain/entities/event/sales-price-formula-deleted.event.ts b/src/modules/transaction/sales-price-formula/domain/entities/event/sales-price-formula-deleted.event.ts deleted file mode 100644 index e843e0c..0000000 --- a/src/modules/transaction/sales-price-formula/domain/entities/event/sales-price-formula-deleted.event.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IEvent } from 'src/core/strings/constants/interface.constants'; - -export class SalesPriceFormulaDeletedEvent { - constructor(public readonly data: IEvent) {} -} diff --git a/src/modules/transaction/sales-price-formula/sales-price-formula.module.ts b/src/modules/transaction/sales-price-formula/sales-price-formula.module.ts index 0fc590a..a6e803f 100644 --- a/src/modules/transaction/sales-price-formula/sales-price-formula.module.ts +++ b/src/modules/transaction/sales-price-formula/sales-price-formula.module.ts @@ -1,4 +1,4 @@ -import { Module } from '@nestjs/common'; +import { Global, Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { TypeOrmModule } from '@nestjs/typeorm'; import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants'; @@ -13,6 +13,7 @@ import { UpdateSalesPriceFormulaManager } from './domain/usecases/managers/updat import { DetailSalesPriceFormulaManager } from './domain/usecases/managers/detail-sales-price-formula.manager'; import { SalesPriceFormulaModel } from './data/models/sales-price-formula.model'; +@Global() @Module({ imports: [ ConfigModule.forRoot(), @@ -33,5 +34,6 @@ import { SalesPriceFormulaModel } from './data/models/sales-price-formula.model' SalesPriceFormulaDataOrchestrator, SalesPriceFormulaReadOrchestrator, ], + exports: [SalesPriceFormulaDataService, SalesPriceFormulaReadService], }) export class SalesPriceFormulaModule {}