feat(SPG-374) REST API Read Kategori VIP
parent
be7eb23c97
commit
d98246063d
|
@ -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<VipCategoryEntity> {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(VipCategoryModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private repo: Repository<VipCategoryModel>,
|
||||||
|
) {
|
||||||
|
super(repo);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity';
|
||||||
|
|
||||||
|
export interface FilterVipCategoryEntity extends BaseFilterEntity {}
|
|
@ -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<VipCategoryEntity> {
|
||||||
|
async prepareData(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async afterProcess(): Promise<void> {
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<VipCategoryEntity> {
|
||||||
|
async prepareData(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async afterProcess(): Promise<void> {
|
||||||
|
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<VipCategoryEntity>,
|
||||||
|
): SelectQueryBuilder<VipCategoryEntity> {
|
||||||
|
return queryBuilder;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<VipCategoryEntity> {
|
||||||
|
constructor(
|
||||||
|
private indexManager: IndexVipCategoryManager,
|
||||||
|
private detailManager: DetailVipCategoryManager,
|
||||||
|
private serviceData: VipCategoryReadService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
async index(params): Promise<PaginationResponse<VipCategoryEntity>> {
|
||||||
|
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<VipCategoryEntity> {
|
||||||
|
this.detailManager.setData(dataId);
|
||||||
|
this.detailManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY);
|
||||||
|
await this.detailManager.execute();
|
||||||
|
return this.detailManager.getResult();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 {}
|
|
@ -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<PaginationResponse<VipCategoryEntity>> {
|
||||||
|
return await this.orchestrator.index(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
async detail(@Param('id') id: string): Promise<VipCategoryEntity> {
|
||||||
|
return await this.orchestrator.detail(id);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue