diff --git a/src/modules/web-information/faq/data/services/faq-read.service.ts b/src/modules/web-information/faq/data/services/faq-read.service.ts new file mode 100644 index 0000000..cfd09be --- /dev/null +++ b/src/modules/web-information/faq/data/services/faq-read.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from '@nestjs/common'; +import { FaqEntity } from '../../domain/entities/faq.entity'; +import { InjectRepository } from '@nestjs/typeorm'; +import { FaqModel } from '../models/faq.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 FaqReadService extends BaseReadService { + constructor( + @InjectRepository(FaqModel, CONNECTION_NAME.DEFAULT) + private repo: Repository, + ) { + super(repo); + } +} diff --git a/src/modules/web-information/faq/domain/entities/filter-faq.entity.ts b/src/modules/web-information/faq/domain/entities/filter-faq.entity.ts new file mode 100644 index 0000000..9488909 --- /dev/null +++ b/src/modules/web-information/faq/domain/entities/filter-faq.entity.ts @@ -0,0 +1,3 @@ +import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity'; + +export interface FilterFaqEntity extends BaseFilterEntity {} diff --git a/src/modules/web-information/faq/domain/usecases/faq-read.orchestrator.ts b/src/modules/web-information/faq/domain/usecases/faq-read.orchestrator.ts new file mode 100644 index 0000000..02e11cb --- /dev/null +++ b/src/modules/web-information/faq/domain/usecases/faq-read.orchestrator.ts @@ -0,0 +1,33 @@ +import { Injectable } from '@nestjs/common'; +import { IndexFaqManager } from './managers/index-faq.manager'; +import { FaqReadService } from '../../data/services/faq-read.service'; +import { FaqEntity } from '../entities/faq.entity'; +import { PaginationResponse } from 'src/core/response/domain/ok-response.interface'; +import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-read.orchestrator'; +import { DetailFaqManager } from './managers/detail-faq.manager'; +import { TABLE_NAME } from 'src/core/strings/constants/table.constants'; + +@Injectable() +export class FaqReadOrchestrator extends BaseReadOrchestrator { + constructor( + private indexManager: IndexFaqManager, + private detailManager: DetailFaqManager, + private serviceData: FaqReadService, + ) { + super(); + } + + async index(params): Promise> { + this.indexManager.setFilterParam(params); + this.indexManager.setService(this.serviceData, TABLE_NAME.FAQ); + await this.indexManager.execute(); + return this.indexManager.getResult(); + } + + async detail(dataId: string): Promise { + this.detailManager.setData(dataId); + this.detailManager.setService(this.serviceData, TABLE_NAME.FAQ); + await this.detailManager.execute(); + return this.detailManager.getResult(); + } +} diff --git a/src/modules/web-information/faq/domain/usecases/managers/detail-faq.manager.ts b/src/modules/web-information/faq/domain/usecases/managers/detail-faq.manager.ts new file mode 100644 index 0000000..a44ee48 --- /dev/null +++ b/src/modules/web-information/faq/domain/usecases/managers/detail-faq.manager.ts @@ -0,0 +1,51 @@ +import { Injectable } from '@nestjs/common'; +import { BaseDetailManager } from 'src/core/modules/domain/usecase/managers/base-detail.manager'; +import { FaqEntity } from '../../entities/faq.entity'; +import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity'; + +@Injectable() +export class DetailFaqManager 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}.created_at`, + `${this.tableName}.creator_name`, + `${this.tableName}.updated_at`, + `${this.tableName}.editor_name`, + `${this.tableName}.title`, + `${this.tableName}.description`, + ]; + } + + get setFindProperties(): any { + return { + id: this.dataId, + }; + } +} diff --git a/src/modules/web-information/faq/domain/usecases/managers/index-faq.manager.ts b/src/modules/web-information/faq/domain/usecases/managers/index-faq.manager.ts new file mode 100644 index 0000000..a1508eb --- /dev/null +++ b/src/modules/web-information/faq/domain/usecases/managers/index-faq.manager.ts @@ -0,0 +1,64 @@ +import { Injectable } from '@nestjs/common'; +import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager'; +import { FaqEntity } from '../../entities/faq.entity'; +import { SelectQueryBuilder } from 'typeorm'; +import { + Param, + RelationParam, +} from 'src/core/modules/domain/entities/base-filter.entity'; + +@Injectable() +export class IndexFaqManager 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}.created_at`, + `${this.tableName}.creator_name`, + `${this.tableName}.updated_at`, + `${this.tableName}.editor_name`, + `${this.tableName}.title`, + `${this.tableName}.description`, + ]; + } + + get specificFilter(): Param[] { + return [ + { + cols: `${this.tableName}.name`, + data: this.filterParam.names, + }, + ]; + } + + setQueryFilter( + queryBuilder: SelectQueryBuilder, + ): SelectQueryBuilder { + return queryBuilder; + } +} diff --git a/src/modules/web-information/faq/infrastructure/dto/filter-faq.dto.ts b/src/modules/web-information/faq/infrastructure/dto/filter-faq.dto.ts new file mode 100644 index 0000000..ce6a148 --- /dev/null +++ b/src/modules/web-information/faq/infrastructure/dto/filter-faq.dto.ts @@ -0,0 +1,4 @@ +import { BaseFilterDto } from 'src/core/modules/infrastructure/dto/base-filter.dto'; +import { FilterFaqEntity } from '../../domain/entities/filter-faq.entity'; + +export class FilterFaqDto extends BaseFilterDto implements FilterFaqEntity {} diff --git a/src/modules/web-information/faq/infrastructure/faq-read.controller.ts b/src/modules/web-information/faq/infrastructure/faq-read.controller.ts new file mode 100644 index 0000000..e282038 --- /dev/null +++ b/src/modules/web-information/faq/infrastructure/faq-read.controller.ts @@ -0,0 +1,30 @@ +import { Controller, Get, Param, Query } from '@nestjs/common'; +import { FilterFaqDto } from './dto/filter-faq.dto'; +import { Pagination } from 'src/core/response'; +import { PaginationResponse } from 'src/core/response/domain/ok-response.interface'; +import { FaqEntity } from '../domain/entities/faq.entity'; +import { FaqReadOrchestrator } from '../domain/usecases/faq-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.FAQ.split('-').join(' ')} - read`) +@Controller(`v1/${MODULE_NAME.FAQ}`) +@Public(false) +@ApiBearerAuth('JWT') +export class FaqReadController { + constructor(private orchestrator: FaqReadOrchestrator) {} + + @Get() + @Pagination() + async index( + @Query() params: FilterFaqDto, + ): Promise> { + return await this.orchestrator.index(params); + } + + @Get(':id') + async detail(@Param('id') id: string): Promise { + return await this.orchestrator.detail(id); + } +}