feat: adiciona filtro de cobrança e converte para query builder no deb.repository
This commit is contained in:
49
src/orders/controllers/deb.controller.ts
Normal file
49
src/orders/controllers/deb.controller.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Query,
|
||||
UsePipes,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
ValidationPipe,
|
||||
} from '@nestjs/common';
|
||||
import { ApiOperation, ApiTags, ApiResponse } from '@nestjs/swagger';
|
||||
import { DebService } from '../application/deb.service';
|
||||
import { DebDto } from '../dto/DebDto';
|
||||
import { FindDebDto } from '../dto/find-deb.dto';
|
||||
|
||||
@ApiTags('Débitos')
|
||||
@Controller('api/v1/deb')
|
||||
export class DebController {
|
||||
constructor(private readonly debService: DebService) {}
|
||||
|
||||
@Get('find-by-cpf')
|
||||
@ApiOperation({
|
||||
summary: 'Busca débitos por CPF/CGCENT',
|
||||
description: 'Busca débitos de um cliente usando CPF ou CGCENT. Opcionalmente pode filtrar por matrícula do funcionário ou código de cobrança.',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Lista de débitos retornada com sucesso',
|
||||
type: [DebDto],
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'CPF/CGCENT é obrigatório',
|
||||
})
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async findByCpfCgcent(
|
||||
@Query() query: FindDebDto,
|
||||
): Promise<DebDto[]> {
|
||||
try {
|
||||
return await this.debService.findByCpfCgcent(query.cpfCgcent, query.matricula, query.cobranca);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar débitos',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user