feat(SPG-331) REST API Read Tax
parent
d7937217ab
commit
abe163e80a
|
@ -0,0 +1,17 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { TaxEntity } from '../../domain/entities/tax.entity';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { TaxModel } from '../models/tax.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 TaxReadService extends BaseReadService<TaxEntity> {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(TaxModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private repo: Repository<TaxModel>,
|
||||||
|
) {
|
||||||
|
super(repo);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity';
|
||||||
|
|
||||||
|
export interface FilterTaxEntity extends BaseFilterEntity {
|
||||||
|
values: string[];
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseDetailManager } from 'src/core/modules/domain/usecase/managers/base-detail.manager';
|
||||||
|
import { TaxEntity } from '../../entities/tax.entity';
|
||||||
|
import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class DetailTaxManager extends BaseDetailManager<TaxEntity> {
|
||||||
|
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}.value`,
|
||||||
|
`${this.tableName}.created_at`,
|
||||||
|
`${this.tableName}.updated_at`,
|
||||||
|
`${this.tableName}.creator_id`,
|
||||||
|
`${this.tableName}.editor_id`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
get setFindProperties(): any {
|
||||||
|
return {
|
||||||
|
id: this.dataId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager';
|
||||||
|
import { TaxEntity } from '../../entities/tax.entity';
|
||||||
|
import { SelectQueryBuilder } from 'typeorm';
|
||||||
|
import {
|
||||||
|
Param,
|
||||||
|
RelationParam,
|
||||||
|
} from 'src/core/modules/domain/entities/base-filter.entity';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class IndexTaxManager extends BaseIndexManager<TaxEntity> {
|
||||||
|
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}.value`,
|
||||||
|
`${this.tableName}.created_at`,
|
||||||
|
`${this.tableName}.updated_at`,
|
||||||
|
`${this.tableName}.creator_id`,
|
||||||
|
`${this.tableName}.editor_id`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
get specificFilter(): Param[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
cols: `${this.tableName}.name`,
|
||||||
|
data: this.filterParam.names,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cols: `${this.tableName}.value`,
|
||||||
|
data: this.filterParam.values,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
setQueryFilter(
|
||||||
|
queryBuilder: SelectQueryBuilder<TaxEntity>,
|
||||||
|
): SelectQueryBuilder<TaxEntity> {
|
||||||
|
return queryBuilder;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { IndexTaxManager } from './managers/index-tax.manager';
|
||||||
|
import { TaxReadService } from '../../data/services/tax-read.service';
|
||||||
|
import { TaxEntity } from '../entities/tax.entity';
|
||||||
|
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-read.orchestrator';
|
||||||
|
import { DetailTaxManager } from './managers/detail-tax.manager';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class TaxReadOrchestrator extends BaseReadOrchestrator<TaxEntity> {
|
||||||
|
constructor(
|
||||||
|
private indexManager: IndexTaxManager,
|
||||||
|
private detailManager: DetailTaxManager,
|
||||||
|
private serviceData: TaxReadService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
async index(params): Promise<PaginationResponse<TaxEntity>> {
|
||||||
|
this.indexManager.setFilterParam(params);
|
||||||
|
this.indexManager.setService(this.serviceData, TABLE_NAME.TAX);
|
||||||
|
await this.indexManager.execute();
|
||||||
|
return this.indexManager.getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
async detail(dataId: string): Promise<TaxEntity> {
|
||||||
|
this.detailManager.setData(dataId);
|
||||||
|
this.detailManager.setService(this.serviceData, TABLE_NAME.TAX);
|
||||||
|
await this.detailManager.execute();
|
||||||
|
return this.detailManager.getResult();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { BaseFilterDto } from 'src/core/modules/infrastructure/dto/base-filter.dto';
|
||||||
|
import { FilterTaxEntity } from '../../domain/entities/filter-tax.entity';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { Transform } from 'class-transformer';
|
||||||
|
|
||||||
|
export class FilterTaxDto extends BaseFilterDto implements FilterTaxEntity {
|
||||||
|
@ApiProperty({ type: ['string'], required: false })
|
||||||
|
@Transform((body) => {
|
||||||
|
return Array.isArray(body.value) ? body.value : [body.value];
|
||||||
|
})
|
||||||
|
values: string[];
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
import { Controller, Get, Param, Query } from '@nestjs/common';
|
||||||
|
import { FilterTaxDto } from './dto/filter-tax.dto';
|
||||||
|
import { Pagination } from 'src/core/response';
|
||||||
|
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { TaxEntity } from '../domain/entities/tax.entity';
|
||||||
|
import { TaxReadOrchestrator } from '../domain/usecases/tax-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.TAX.split('-').join(' ')} - read`)
|
||||||
|
@Controller(MODULE_NAME.TAX)
|
||||||
|
@Public(false)
|
||||||
|
@ApiBearerAuth('JWT')
|
||||||
|
export class TaxReadController {
|
||||||
|
constructor(private orchestrator: TaxReadOrchestrator) {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
@Pagination()
|
||||||
|
async index(
|
||||||
|
@Query() params: FilterTaxDto,
|
||||||
|
): Promise<PaginationResponse<TaxEntity>> {
|
||||||
|
return await this.orchestrator.index(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
async detail(@Param('id') id: string): Promise<TaxEntity> {
|
||||||
|
return await this.orchestrator.detail(id);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue