feat: adiciona filtro de cobrança e converte para query builder no deb.repository

This commit is contained in:
JurTI-BR
2025-11-02 15:15:17 -03:00
parent 893a7c5b0a
commit 3849fa1c4e
4 changed files with 184 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import { DebRepository } from '../repositories/deb.repository';
import { DebDto } from '../dto/DebDto';
@Injectable()
export class DebService {
constructor(
private readonly debRepository: DebRepository,
) {}
/**
* Busca débitos por CPF ou CGCENT
* @param cpfCgcent - CPF ou CGCENT do cliente
* @param matricula - Matrícula do funcionário (opcional)
* @param cobranca - Código de cobrança (opcional)
* @returns Lista de débitos do cliente
*/
async findByCpfCgcent(cpfCgcent: string, matricula?: number, cobranca?: string): Promise<DebDto[]> {
if (!cpfCgcent) {
throw new HttpException('CPF/CGCENT é obrigatório', HttpStatus.BAD_REQUEST);
}
try {
const result = await this.debRepository.findByCpfCgcent(cpfCgcent, matricula, cobranca);
return result as DebDto[];
} catch (error) {
throw new HttpException(
error.message || 'Erro ao buscar débitos',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
}