diff --git a/src/modules/transaction/vip-category/data/services/vip-category-read.service.ts b/src/modules/transaction/vip-category/data/services/vip-category-read.service.ts new file mode 100644 index 0000000..ef61e78 --- /dev/null +++ b/src/modules/transaction/vip-category/data/services/vip-category-read.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from '@nestjs/common'; +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'; +import { BaseReadService } from 'src/core/modules/data/service/base-read.service'; + +@Injectable() +export class VipCategoryReadService extends BaseReadService { + constructor( + @InjectRepository(VipCategoryModel, CONNECTION_NAME.DEFAULT) + private repo: Repository, + ) { + super(repo); + } +} diff --git a/src/modules/transaction/vip-category/domain/entities/filter-vip-category.entity.ts b/src/modules/transaction/vip-category/domain/entities/filter-vip-category.entity.ts new file mode 100644 index 0000000..bb53a73 --- /dev/null +++ b/src/modules/transaction/vip-category/domain/entities/filter-vip-category.entity.ts @@ -0,0 +1,3 @@ +import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity'; + +export interface FilterVipCategoryEntity extends BaseFilterEntity {} diff --git a/src/modules/transaction/vip-category/domain/usecases/managers/detail-vip-category.manager.ts b/src/modules/transaction/vip-category/domain/usecases/managers/detail-vip-category.manager.ts new file mode 100644 index 0000000..aa7c1cf --- /dev/null +++ b/src/modules/transaction/vip-category/domain/usecases/managers/detail-vip-category.manager.ts @@ -0,0 +1,50 @@ +import { Injectable } from '@nestjs/common'; +import { BaseDetailManager } from 'src/core/modules/domain/usecase/managers/base-detail.manager'; +import { VipCategoryEntity } from '../../entities/vip-category.entity'; +import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity'; + +@Injectable() +export class DetailVipCategoryManager 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}.name`, + `${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/vip-category/domain/usecases/managers/index-vip-category.manager.ts b/src/modules/transaction/vip-category/domain/usecases/managers/index-vip-category.manager.ts new file mode 100644 index 0000000..5e948e1 --- /dev/null +++ b/src/modules/transaction/vip-category/domain/usecases/managers/index-vip-category.manager.ts @@ -0,0 +1,63 @@ +import { Injectable } from '@nestjs/common'; +import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager'; +import { VipCategoryEntity } from '../../entities/vip-category.entity'; +import { SelectQueryBuilder } from 'typeorm'; +import { + Param, + RelationParam, +} from 'src/core/modules/domain/entities/base-filter.entity'; + +@Injectable() +export class IndexVipCategoryManager 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}.name`, + `${this.tableName}.created_at`, + `${this.tableName}.updated_at`, + `${this.tableName}.creator_name`, + `${this.tableName}.editor_name`, + ]; + } + + get specificFilter(): Param[] { + return [ + { + cols: `${this.tableName}.name`, + data: this.filterParam.names, + }, + ]; + } + + setQueryFilter( + queryBuilder: SelectQueryBuilder, + ): SelectQueryBuilder { + return queryBuilder; + } +} diff --git a/src/modules/transaction/vip-category/domain/usecases/vip-category-read.orchestrator.ts b/src/modules/transaction/vip-category/domain/usecases/vip-category-read.orchestrator.ts new file mode 100644 index 0000000..6513f21 --- /dev/null +++ b/src/modules/transaction/vip-category/domain/usecases/vip-category-read.orchestrator.ts @@ -0,0 +1,33 @@ +import { Injectable } from '@nestjs/common'; +import { IndexVipCategoryManager } from './managers/index-vip-category.manager'; +import { VipCategoryReadService } from '../../data/services/vip-category-read.service'; +import { VipCategoryEntity } from '../entities/vip-category.entity'; +import { PaginationResponse } from 'src/core/response/domain/ok-response.interface'; +import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-read.orchestrator'; +import { DetailVipCategoryManager } from './managers/detail-vip-category.manager'; +import { TABLE_NAME } from 'src/core/strings/constants/table.constants'; + +@Injectable() +export class VipCategoryReadOrchestrator extends BaseReadOrchestrator { + constructor( + private indexManager: IndexVipCategoryManager, + private detailManager: DetailVipCategoryManager, + private serviceData: VipCategoryReadService, + ) { + super(); + } + + async index(params): Promise> { + this.indexManager.setFilterParam(params); + this.indexManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY); + await this.indexManager.execute(); + return this.indexManager.getResult(); + } + + async detail(dataId: string): Promise { + this.detailManager.setData(dataId); + this.detailManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY); + await this.detailManager.execute(); + return this.detailManager.getResult(); + } +} diff --git a/src/modules/transaction/vip-category/infrastructure/dto/filter-vip-category.dto.ts b/src/modules/transaction/vip-category/infrastructure/dto/filter-vip-category.dto.ts new file mode 100644 index 0000000..12cc304 --- /dev/null +++ b/src/modules/transaction/vip-category/infrastructure/dto/filter-vip-category.dto.ts @@ -0,0 +1,6 @@ +import { BaseFilterDto } from 'src/core/modules/infrastructure/dto/base-filter.dto'; +import { FilterVipCategoryEntity } from '../../domain/entities/filter-vip-category.entity'; + +export class FilterVipCategoryDto + extends BaseFilterDto + implements FilterVipCategoryEntity {} diff --git a/src/modules/transaction/vip-category/infrastructure/vip-category-read.controller.ts b/src/modules/transaction/vip-category/infrastructure/vip-category-read.controller.ts new file mode 100644 index 0000000..6a3be6b --- /dev/null +++ b/src/modules/transaction/vip-category/infrastructure/vip-category-read.controller.ts @@ -0,0 +1,30 @@ +import { Controller, Get, Param, Query } from '@nestjs/common'; +import { FilterVipCategoryDto } from './dto/filter-vip-category.dto'; +import { Pagination } from 'src/core/response'; +import { PaginationResponse } from 'src/core/response/domain/ok-response.interface'; +import { VipCategoryEntity } from '../domain/entities/vip-category.entity'; +import { VipCategoryReadOrchestrator } from '../domain/usecases/vip-category-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.VIP_CATEGORY.split('-').join(' ')} - read`) +@Controller(MODULE_NAME.VIP_CATEGORY) +@Public(false) +@ApiBearerAuth('JWT') +export class VipCategoryReadController { + constructor(private orchestrator: VipCategoryReadOrchestrator) {} + + @Get() + @Pagination() + async index( + @Query() params: FilterVipCategoryDto, + ): Promise> { + return await this.orchestrator.index(params); + } + + @Get(':id') + async detail(@Param('id') id: string): Promise { + return await this.orchestrator.detail(id); + } +}