From af1a642907e69b0cba81c698dbc36c43b513f850 Mon Sep 17 00:00:00 2001 From: Aswin Ashar Abdullah Date: Mon, 15 Jul 2024 14:28:45 +0700 Subject: [PATCH] feat(SPG-428) REST API Read Data Gate --- .../infrastructure/constant.controller.ts | 6 ++ .../domain/entities/filter-refund.entity.ts | 17 +--- .../gate/data/services/gate-read.service.ts | 17 ++++ .../domain/entities/filter-gate.entity.ts | 8 ++ .../domain/usecases/gate-read.orchestrator.ts | 33 ++++++++ .../usecases/managers/detail-gate.manager.ts | 59 +++++++++++++ .../usecases/managers/index-gate.manager.ts | 84 +++++++++++++++++++ .../infrastructure/dto/filter-gate.dto.ts | 30 +++++++ .../infrastructure/gate-read.controller.ts | 30 +++++++ 9 files changed, 268 insertions(+), 16 deletions(-) create mode 100644 src/modules/web-information/gate/data/services/gate-read.service.ts create mode 100644 src/modules/web-information/gate/domain/entities/filter-gate.entity.ts create mode 100644 src/modules/web-information/gate/domain/usecases/gate-read.orchestrator.ts create mode 100644 src/modules/web-information/gate/domain/usecases/managers/detail-gate.manager.ts create mode 100644 src/modules/web-information/gate/domain/usecases/managers/index-gate.manager.ts create mode 100644 src/modules/web-information/gate/infrastructure/dto/filter-gate.dto.ts create mode 100644 src/modules/web-information/gate/infrastructure/gate-read.controller.ts diff --git a/src/modules/configuration/constant/infrastructure/constant.controller.ts b/src/modules/configuration/constant/infrastructure/constant.controller.ts index 99c6d99..a388236 100644 --- a/src/modules/configuration/constant/infrastructure/constant.controller.ts +++ b/src/modules/configuration/constant/infrastructure/constant.controller.ts @@ -6,6 +6,7 @@ import { ItemType } from 'src/modules/item-related/item-category/constants'; import { LimitType } from 'src/modules/item-related/item/constants'; import { PaymentMethodType } from 'src/modules/transaction/payment-method/constants'; import { RefundType } from 'src/modules/transaction/refund/constants'; +import { GateType } from 'src/modules/web-information/gate/constants'; @ApiTags('configuration - constant') @Controller('v1/constant') @@ -50,4 +51,9 @@ export class ConstantController { async refundType(): Promise { return Object.values(RefundType); } + + @Get('gate-type') + async gateType(): Promise { + return Object.values(GateType); + } } diff --git a/src/modules/transaction/refund/domain/entities/filter-refund.entity.ts b/src/modules/transaction/refund/domain/entities/filter-refund.entity.ts index 42aba39..4232869 100644 --- a/src/modules/transaction/refund/domain/entities/filter-refund.entity.ts +++ b/src/modules/transaction/refund/domain/entities/filter-refund.entity.ts @@ -1,18 +1,3 @@ import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity'; -export interface FilterRefundEntity extends BaseFilterEntity { - codes: string[]; - invoice_codes: string[]; - bank_names: string[]; - bank_account_names: string[]; - bank_account_numbers: string[]; - contact_names: string[]; - creator_names: string[]; - - refund_date_from: Date; - refund_date_to: Date; - request_date_from: Date; - request_date_to: Date; - settlement_date_from: Date; - settlement_date_to: Date; -} +export interface FilterRefundEntity extends BaseFilterEntity {} diff --git a/src/modules/web-information/gate/data/services/gate-read.service.ts b/src/modules/web-information/gate/data/services/gate-read.service.ts new file mode 100644 index 0000000..0dc74f2 --- /dev/null +++ b/src/modules/web-information/gate/data/services/gate-read.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from '@nestjs/common'; +import { GateEntity } from '../../domain/entities/gate.entity'; +import { InjectRepository } from '@nestjs/typeorm'; +import { GateModel } from '../models/gate.model'; +import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants'; +import { Repository } from 'typeorm'; +import { BaseReadService } from 'src/core/modules/data/service/base-read.service'; + +@Injectable() +export class GateReadService extends BaseReadService { + constructor( + @InjectRepository(GateModel, CONNECTION_NAME.DEFAULT) + private repo: Repository, + ) { + super(repo); + } +} diff --git a/src/modules/web-information/gate/domain/entities/filter-gate.entity.ts b/src/modules/web-information/gate/domain/entities/filter-gate.entity.ts new file mode 100644 index 0000000..36e1f08 --- /dev/null +++ b/src/modules/web-information/gate/domain/entities/filter-gate.entity.ts @@ -0,0 +1,8 @@ +import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity'; + +export interface FilterGateEntity extends BaseFilterEntity { + codes: string[]; + types: string[]; + item_names: string[]; + notes: string[]; +} diff --git a/src/modules/web-information/gate/domain/usecases/gate-read.orchestrator.ts b/src/modules/web-information/gate/domain/usecases/gate-read.orchestrator.ts new file mode 100644 index 0000000..d7ed7f6 --- /dev/null +++ b/src/modules/web-information/gate/domain/usecases/gate-read.orchestrator.ts @@ -0,0 +1,33 @@ +import { Injectable } from '@nestjs/common'; +import { IndexGateManager } from './managers/index-gate.manager'; +import { GateReadService } from '../../data/services/gate-read.service'; +import { GateEntity } from '../entities/gate.entity'; +import { PaginationResponse } from 'src/core/response/domain/ok-response.interface'; +import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-read.orchestrator'; +import { DetailGateManager } from './managers/detail-gate.manager'; +import { TABLE_NAME } from 'src/core/strings/constants/table.constants'; + +@Injectable() +export class GateReadOrchestrator extends BaseReadOrchestrator { + constructor( + private indexManager: IndexGateManager, + private detailManager: DetailGateManager, + private serviceData: GateReadService, + ) { + super(); + } + + async index(params): Promise> { + this.indexManager.setFilterParam(params); + this.indexManager.setService(this.serviceData, TABLE_NAME.GATE); + await this.indexManager.execute(); + return this.indexManager.getResult(); + } + + async detail(dataId: string): Promise { + this.detailManager.setData(dataId); + this.detailManager.setService(this.serviceData, TABLE_NAME.GATE); + await this.detailManager.execute(); + return this.detailManager.getResult(); + } +} diff --git a/src/modules/web-information/gate/domain/usecases/managers/detail-gate.manager.ts b/src/modules/web-information/gate/domain/usecases/managers/detail-gate.manager.ts new file mode 100644 index 0000000..39fdf54 --- /dev/null +++ b/src/modules/web-information/gate/domain/usecases/managers/detail-gate.manager.ts @@ -0,0 +1,59 @@ +import { Injectable } from '@nestjs/common'; +import { BaseDetailManager } from 'src/core/modules/domain/usecase/managers/base-detail.manager'; +import { GateEntity } from '../../entities/gate.entity'; +import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity'; + +@Injectable() +export class DetailGateManager 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: ['item'], + + // relation yang hanya ingin dihitung (akan return number) + countRelations: [], + }; + } + + get selects(): string[] { + return [ + `${this.tableName}.id`, + `${this.tableName}.status`, + `${this.tableName}.creator_name`, + `${this.tableName}.created_at`, + `${this.tableName}.updated_at`, + `${this.tableName}.editor_name`, + `${this.tableName}.type`, + `${this.tableName}.code`, + `${this.tableName}.note`, + + 'item.id', + 'item.name', + 'item.status', + 'item.item_type', + 'item.base_price', + 'item.hpp', + ]; + } + + get setFindProperties(): any { + return { + id: this.dataId, + }; + } +} diff --git a/src/modules/web-information/gate/domain/usecases/managers/index-gate.manager.ts b/src/modules/web-information/gate/domain/usecases/managers/index-gate.manager.ts new file mode 100644 index 0000000..0298552 --- /dev/null +++ b/src/modules/web-information/gate/domain/usecases/managers/index-gate.manager.ts @@ -0,0 +1,84 @@ +import { Injectable } from '@nestjs/common'; +import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager'; +import { GateEntity } from '../../entities/gate.entity'; +import { SelectQueryBuilder } from 'typeorm'; +import { + Param, + RelationParam, +} from 'src/core/modules/domain/entities/base-filter.entity'; + +@Injectable() +export class IndexGateManager 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: ['item'], + + // relation yang hanya ingin dihitung (akan return number) + countRelations: [], + }; + } + + get selects(): string[] { + return [ + `${this.tableName}.id`, + `${this.tableName}.status`, + `${this.tableName}.creator_name`, + `${this.tableName}.created_at`, + `${this.tableName}.updated_at`, + `${this.tableName}.editor_name`, + `${this.tableName}.type`, + `${this.tableName}.code`, + `${this.tableName}.note`, + + 'item.id', + 'item.name', + 'item.status', + 'item.item_type', + 'item.base_price', + 'item.hpp', + ]; + } + + get specificFilter(): Param[] { + return [ + { + cols: `${this.tableName}.code`, + data: this.filterParam.codes, + }, + { + cols: `${this.tableName}.type`, + data: this.filterParam.types, + }, + { + cols: `${this.tableName}.note`, + data: this.filterParam.notes, + }, + { + cols: `item.name`, + data: this.filterParam.item_names, + }, + ]; + } + + setQueryFilter( + queryBuilder: SelectQueryBuilder, + ): SelectQueryBuilder { + return queryBuilder; + } +} diff --git a/src/modules/web-information/gate/infrastructure/dto/filter-gate.dto.ts b/src/modules/web-information/gate/infrastructure/dto/filter-gate.dto.ts new file mode 100644 index 0000000..d3da747 --- /dev/null +++ b/src/modules/web-information/gate/infrastructure/dto/filter-gate.dto.ts @@ -0,0 +1,30 @@ +import { BaseFilterDto } from 'src/core/modules/infrastructure/dto/base-filter.dto'; +import { FilterGateEntity } from '../../domain/entities/filter-gate.entity'; +import { ApiProperty } from '@nestjs/swagger'; +import { Transform } from 'class-transformer'; + +export class FilterGateDto extends BaseFilterDto implements FilterGateEntity { + @ApiProperty({ type: ['string'], required: false }) + @Transform((body) => { + return Array.isArray(body.value) ? body.value : [body.value]; + }) + codes: string[]; + + @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]; + }) + item_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/web-information/gate/infrastructure/gate-read.controller.ts b/src/modules/web-information/gate/infrastructure/gate-read.controller.ts new file mode 100644 index 0000000..b6d213a --- /dev/null +++ b/src/modules/web-information/gate/infrastructure/gate-read.controller.ts @@ -0,0 +1,30 @@ +import { Controller, Get, Param, Query } from '@nestjs/common'; +import { FilterGateDto } from './dto/filter-gate.dto'; +import { Pagination } from 'src/core/response'; +import { PaginationResponse } from 'src/core/response/domain/ok-response.interface'; +import { GateEntity } from '../domain/entities/gate.entity'; +import { GateReadOrchestrator } from '../domain/usecases/gate-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.GATE.split('-').join(' ')} - read`) +@Controller(`v1/${MODULE_NAME.GATE}`) +@Public(false) +@ApiBearerAuth('JWT') +export class GateReadController { + constructor(private orchestrator: GateReadOrchestrator) {} + + @Get() + @Pagination() + async index( + @Query() params: FilterGateDto, + ): Promise> { + return await this.orchestrator.index(params); + } + + @Get(':id') + async detail(@Param('id') id: string): Promise { + return await this.orchestrator.detail(id); + } +}