feat(SPG-336) REST API Read Item Category
parent
63b9a3028a
commit
33f269b56b
|
@ -0,0 +1,17 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { ItemCategoryEntity } from '../../domain/entities/item-category.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { ItemCategoryModel } from '../models/item-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 ItemCategoryReadService extends BaseReadService<ItemCategoryEntity> {
|
||||
constructor(
|
||||
@InjectRepository(ItemCategoryModel, CONNECTION_NAME.DEFAULT)
|
||||
private repo: Repository<ItemCategoryModel>,
|
||||
) {
|
||||
super(repo);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity';
|
||||
|
||||
export interface FilterItemCategoryEntity extends BaseFilterEntity {
|
||||
item_types: string[];
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { IndexItemCategoryManager } from './managers/index-item-category.manager';
|
||||
import { ItemCategoryReadService } from '../../data/services/item-category-read.service';
|
||||
import { ItemCategoryEntity } from '../entities/item-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 { DetailItemCategoryManager } from './managers/detail-item-category.manager';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
|
||||
@Injectable()
|
||||
export class ItemCategoryReadOrchestrator extends BaseReadOrchestrator<ItemCategoryEntity> {
|
||||
constructor(
|
||||
private indexManager: IndexItemCategoryManager,
|
||||
private detailManager: DetailItemCategoryManager,
|
||||
private serviceData: ItemCategoryReadService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async index(params): Promise<PaginationResponse<ItemCategoryEntity>> {
|
||||
this.indexManager.setFilterParam(params);
|
||||
this.indexManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY);
|
||||
await this.indexManager.execute();
|
||||
return this.indexManager.getResult();
|
||||
}
|
||||
|
||||
async detail(dataId: string): Promise<ItemCategoryEntity> {
|
||||
this.detailManager.setData(dataId);
|
||||
this.detailManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY);
|
||||
await this.detailManager.execute();
|
||||
return this.detailManager.getResult();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseDetailManager } from 'src/core/modules/domain/usecase/managers/base-detail.manager';
|
||||
import { ItemCategoryEntity } from '../../entities/item-category.entity';
|
||||
import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity';
|
||||
|
||||
@Injectable()
|
||||
export class DetailItemCategoryManager extends BaseDetailManager<ItemCategoryEntity> {
|
||||
async prepareData(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get relations(): RelationParam {
|
||||
return {
|
||||
joinRelations: [],
|
||||
selectRelations: [],
|
||||
countRelations: [],
|
||||
};
|
||||
}
|
||||
|
||||
get selects(): string[] {
|
||||
return [
|
||||
`${this.tableName}.id`,
|
||||
`${this.tableName}.status`,
|
||||
`${this.tableName}.name`,
|
||||
`${this.tableName}.item_type`,
|
||||
`${this.tableName}.created_at`,
|
||||
`${this.tableName}.creator_name`,
|
||||
`${this.tableName}.updated_at`,
|
||||
`${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 { ItemCategoryEntity } from '../../entities/item-category.entity';
|
||||
import { SelectQueryBuilder } from 'typeorm';
|
||||
import {
|
||||
Param,
|
||||
RelationParam,
|
||||
} from 'src/core/modules/domain/entities/base-filter.entity';
|
||||
|
||||
@Injectable()
|
||||
export class IndexItemCategoryManager extends BaseIndexManager<ItemCategoryEntity> {
|
||||
async prepareData(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get relations(): RelationParam {
|
||||
return {
|
||||
joinRelations: [],
|
||||
selectRelations: [],
|
||||
countRelations: [],
|
||||
};
|
||||
}
|
||||
|
||||
get selects(): string[] {
|
||||
return [
|
||||
`${this.tableName}.id`,
|
||||
`${this.tableName}.status`,
|
||||
`${this.tableName}.name`,
|
||||
`${this.tableName}.item_type`,
|
||||
`${this.tableName}.created_at`,
|
||||
`${this.tableName}.creator_name`,
|
||||
`${this.tableName}.updated_at`,
|
||||
`${this.tableName}.editor_name`,
|
||||
];
|
||||
}
|
||||
|
||||
get specificFilter(): Param[] {
|
||||
return [
|
||||
{
|
||||
cols: `${this.tableName}.name`,
|
||||
data: this.filterParam.names,
|
||||
},
|
||||
{
|
||||
cols: `${this.tableName}.item_type::text`,
|
||||
data: this.filterParam.item_types,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
setQueryFilter(
|
||||
queryBuilder: SelectQueryBuilder<ItemCategoryEntity>,
|
||||
): SelectQueryBuilder<ItemCategoryEntity> {
|
||||
return queryBuilder;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
import { BaseFilterDto } from 'src/core/modules/infrastructure/dto/base-filter.dto';
|
||||
import { FilterItemCategoryEntity } from '../../domain/entities/filter-item-category.entity';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
|
||||
export class FilterItemCategoryDto
|
||||
extends BaseFilterDto
|
||||
implements FilterItemCategoryEntity
|
||||
{
|
||||
@ApiProperty({ type: ['string'], required: false })
|
||||
@Transform((body) => {
|
||||
return Array.isArray(body.value) ? body.value : [body.value];
|
||||
})
|
||||
item_types: string[];
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
import { Controller, Get, Param, Query } from '@nestjs/common';
|
||||
import { FilterItemCategoryDto } from './dto/filter-item-category.dto';
|
||||
import { Pagination } from 'src/core/response';
|
||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||
import { ItemCategoryEntity } from '../domain/entities/item-category.entity';
|
||||
import { ItemCategoryReadOrchestrator } from '../domain/usecases/item-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.ITEM_CATEGORY.split('-').join(' ')} - read`)
|
||||
@Controller(MODULE_NAME.ITEM_CATEGORY)
|
||||
@Public(false)
|
||||
@ApiBearerAuth('JWT')
|
||||
export class ItemCategoryReadController {
|
||||
constructor(private orchestrator: ItemCategoryReadOrchestrator) {}
|
||||
|
||||
@Get()
|
||||
@Pagination()
|
||||
async index(
|
||||
@Query() params: FilterItemCategoryDto,
|
||||
): Promise<PaginationResponse<ItemCategoryEntity>> {
|
||||
return await this.orchestrator.index(params);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async detail(@Param('id') id: string): Promise<ItemCategoryEntity> {
|
||||
return await this.orchestrator.detail(id);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue