diff --git a/src/modules/transaction/payment-method/domain/entities/filter-payment-method.entity.ts b/src/modules/transaction/payment-method/domain/entities/filter-payment-method.entity.ts new file mode 100644 index 0000000..3519c51 --- /dev/null +++ b/src/modules/transaction/payment-method/domain/entities/filter-payment-method.entity.ts @@ -0,0 +1,9 @@ +import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity'; + +export interface FilterPaymentMethodEntity extends BaseFilterEntity { + types: string[]; + issuers: string[]; + account_numbers: string[]; + account_names: string[]; + notes: string[]; +} diff --git a/src/modules/transaction/payment-method/domain/usecases/managers/detail-payment-method.manager.ts b/src/modules/transaction/payment-method/domain/usecases/managers/detail-payment-method.manager.ts new file mode 100644 index 0000000..bf64458 --- /dev/null +++ b/src/modules/transaction/payment-method/domain/usecases/managers/detail-payment-method.manager.ts @@ -0,0 +1,55 @@ +import { Injectable } from '@nestjs/common'; +import { BaseDetailManager } from 'src/core/modules/domain/usecase/managers/base-detail.manager'; +import { PaymentMethodEntity } from '../../entities/payment-method.entity'; +import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity'; + +@Injectable() +export class DetailPaymentMethodManager 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 [ + `${this.tableName}.id`, + `${this.tableName}.status`, + `${this.tableName}.type`, + `${this.tableName}.issuer_name`, + `${this.tableName}.account_number`, + `${this.tableName}.account_name`, + `${this.tableName}.qr_image`, + `${this.tableName}.note`, + `${this.tableName}.created_at`, + `${this.tableName}.updated_at`, + `${this.tableName}.creator_name`, + `${this.tableName}.editor_name`, + ]; + } + + get setFindProperties(): any { + return { + id: this.dataId, + }; + } +} diff --git a/src/modules/transaction/payment-method/domain/usecases/managers/index-payment-method.manager.ts b/src/modules/transaction/payment-method/domain/usecases/managers/index-payment-method.manager.ts new file mode 100644 index 0000000..52cbb4a --- /dev/null +++ b/src/modules/transaction/payment-method/domain/usecases/managers/index-payment-method.manager.ts @@ -0,0 +1,88 @@ +import { Injectable } from '@nestjs/common'; +import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager'; +import { PaymentMethodEntity } from '../../entities/payment-method.entity'; +import { SelectQueryBuilder } from 'typeorm'; +import { + Param, + RelationParam, +} from 'src/core/modules/domain/entities/base-filter.entity'; + +@Injectable() +export class IndexPaymentMethodManager extends BaseIndexManager { + 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 [ + `${this.tableName}.id`, + `${this.tableName}.status`, + `${this.tableName}.type`, + `${this.tableName}.issuer_name`, + `${this.tableName}.account_number`, + `${this.tableName}.account_name`, + `${this.tableName}.qr_image`, + `${this.tableName}.note`, + `${this.tableName}.created_at`, + `${this.tableName}.updated_at`, + `${this.tableName}.creator_name`, + `${this.tableName}.editor_name`, + ]; + } + + get specificFilter(): Param[] { + return [ + { + cols: `${this.tableName}.issuer_name`, + data: this.filterParam.names, + }, + { + cols: `${this.tableName}.issuer_name`, + data: this.filterParam.issuers, + }, + { + cols: `${this.tableName}.type`, + data: this.filterParam.types, + }, + { + cols: `${this.tableName}.account_number`, + data: this.filterParam.account_numbers, + }, + { + cols: `${this.tableName}.account_name`, + data: this.filterParam.account_names, + }, + { + cols: `${this.tableName}.note`, + data: this.filterParam.notes, + }, + ]; + } + + setQueryFilter( + queryBuilder: SelectQueryBuilder, + ): SelectQueryBuilder { + return queryBuilder; + } +} diff --git a/src/modules/transaction/payment-method/domain/usecases/payment-method-read.orchestrator.ts b/src/modules/transaction/payment-method/domain/usecases/payment-method-read.orchestrator.ts new file mode 100644 index 0000000..e274753 --- /dev/null +++ b/src/modules/transaction/payment-method/domain/usecases/payment-method-read.orchestrator.ts @@ -0,0 +1,33 @@ +import { Injectable } from '@nestjs/common'; +import { IndexPaymentMethodManager } from './managers/index-payment-method.manager'; +import { PaymentMethodReadService } from '../../data/services/payment-method-read.service'; +import { PaymentMethodEntity } from '../entities/payment-method.entity'; +import { PaginationResponse } from 'src/core/response/domain/ok-response.interface'; +import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-read.orchestrator'; +import { DetailPaymentMethodManager } from './managers/detail-payment-method.manager'; +import { TABLE_NAME } from 'src/core/strings/constants/table.constants'; + +@Injectable() +export class PaymentMethodReadOrchestrator extends BaseReadOrchestrator { + constructor( + private indexManager: IndexPaymentMethodManager, + private detailManager: DetailPaymentMethodManager, + private serviceData: PaymentMethodReadService, + ) { + super(); + } + + async index(params): Promise> { + this.indexManager.setFilterParam(params); + this.indexManager.setService(this.serviceData, TABLE_NAME.PAYMENT_METHOD); + await this.indexManager.execute(); + return this.indexManager.getResult(); + } + + async detail(dataId: string): Promise { + this.detailManager.setData(dataId); + this.detailManager.setService(this.serviceData, TABLE_NAME.PAYMENT_METHOD); + await this.detailManager.execute(); + return this.detailManager.getResult(); + } +} diff --git a/src/modules/transaction/payment-method/infrastructure/dto/filter-payment-method.dto.ts b/src/modules/transaction/payment-method/infrastructure/dto/filter-payment-method.dto.ts new file mode 100644 index 0000000..29490f8 --- /dev/null +++ b/src/modules/transaction/payment-method/infrastructure/dto/filter-payment-method.dto.ts @@ -0,0 +1,39 @@ +import { BaseFilterDto } from 'src/core/modules/infrastructure/dto/base-filter.dto'; +import { FilterPaymentMethodEntity } from '../../domain/entities/filter-payment-method.entity'; +import { ApiProperty } from '@nestjs/swagger'; +import { Transform } from 'class-transformer'; + +export class FilterPaymentMethodDto + extends BaseFilterDto + implements FilterPaymentMethodEntity +{ + @ApiProperty({ type: ['string'], required: false }) + @Transform((body) => { + return Array.isArray(body.value) ? body.value : [body.value]; + }) + types: string[]; + + @ApiProperty({ type: ['string'], required: false }) + @Transform((body) => { + return Array.isArray(body.value) ? body.value : [body.value]; + }) + issuers: string[]; + + @ApiProperty({ type: ['string'], required: false }) + @Transform((body) => { + return Array.isArray(body.value) ? body.value : [body.value]; + }) + account_numbers: string[]; + + @ApiProperty({ type: ['string'], required: false }) + @Transform((body) => { + return Array.isArray(body.value) ? body.value : [body.value]; + }) + account_names: string[]; + + @ApiProperty({ type: ['string'], required: false }) + @Transform((body) => { + return Array.isArray(body.value) ? body.value : [body.value]; + }) + notes: string[]; +} diff --git a/src/modules/transaction/payment-method/infrastructure/payment-method-read.controller.ts b/src/modules/transaction/payment-method/infrastructure/payment-method-read.controller.ts new file mode 100644 index 0000000..dc0dd77 --- /dev/null +++ b/src/modules/transaction/payment-method/infrastructure/payment-method-read.controller.ts @@ -0,0 +1,30 @@ +import { Controller, Get, Param, Query } from '@nestjs/common'; +import { FilterPaymentMethodDto } from './dto/filter-payment-method.dto'; +import { Pagination } from 'src/core/response'; +import { PaginationResponse } from 'src/core/response/domain/ok-response.interface'; +import { PaymentMethodEntity } from '../domain/entities/payment-method.entity'; +import { PaymentMethodReadOrchestrator } from '../domain/usecases/payment-method-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.PAYMENT_METHOD.split('-').join(' ')} - read`) +@Controller(MODULE_NAME.PAYMENT_METHOD) +@Public(false) +@ApiBearerAuth('JWT') +export class PaymentMethodReadController { + constructor(private orchestrator: PaymentMethodReadOrchestrator) {} + + @Get() + @Pagination() + async index( + @Query() params: FilterPaymentMethodDto, + ): Promise> { + return await this.orchestrator.index(params); + } + + @Get(':id') + async detail(@Param('id') id: string): Promise { + return await this.orchestrator.detail(id); + } +}