commit
This commit is contained in:
24
src/backoffice/category/category.controller.ts
Normal file
24
src/backoffice/category/category.controller.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { CategoryService } from './category.service';
|
||||
import { Controller, Get, HttpException, HttpStatus, Param } from '@nestjs/common';
|
||||
import { ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
|
||||
import { ResultModel } from 'src/domain/models/result.model';
|
||||
|
||||
@ApiTags('BackOffice')
|
||||
@Controller('v1/category')
|
||||
export class CategoryController {
|
||||
|
||||
constructor(private readonly categoryService: CategoryService){}
|
||||
|
||||
@Get(':idSecion')
|
||||
@ApiExcludeEndpoint()
|
||||
async getSection(@Param('idSecion') idSection: number) {
|
||||
try {
|
||||
const result = await this.categoryService.find(idSection);
|
||||
return new ResultModel(true, null, result, []);
|
||||
} catch (error) {
|
||||
throw new HttpException(new ResultModel(false, 'Não foi possível consultar lista de departamentos', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
15
src/backoffice/category/category.module.ts
Normal file
15
src/backoffice/category/category.module.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Pccategoria } from '../../domain/entity/tables/pccategoria.entity';
|
||||
import { CategoryService } from './category.service';
|
||||
import { CategoryController } from './category.controller';
|
||||
import { CacheModule, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
@Module({
|
||||
imports: [CacheModule.register(),
|
||||
TypeOrmModule.forFeature([Pccategoria])],
|
||||
controllers: [
|
||||
CategoryController,],
|
||||
providers: [
|
||||
CategoryService,],
|
||||
})
|
||||
export class CategoryModule { }
|
||||
22
src/backoffice/category/category.service.ts
Normal file
22
src/backoffice/category/category.service.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Pccategoria } from '../../domain/entity/tables/pccategoria.entity';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class CategoryService {
|
||||
constructor(@InjectRepository(Pccategoria)
|
||||
private categoryRespository: Repository<Pccategoria>) { }
|
||||
|
||||
async find(idSecion: number): Promise<Pccategoria[]> {
|
||||
return await this.categoryRespository
|
||||
.createQueryBuilder('pccategoria')
|
||||
.select('"pccategoria".codcategoria', 'codigoCategoria')
|
||||
.addSelect('concat(concat("pccategoria".codcategoria, \'-\'),"pccategoria".categoria)', 'descricaoCategoria')
|
||||
//.addSelect('concat(concat("pccategoria".codcategoria, \'-\'),"pccategoria".categoria)', 'descricaoCategoria')
|
||||
.where("codsec = :codsec", { codsec: idSecion })
|
||||
.getRawMany();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user