feat: adiciona filtro de cobrança e converte para query builder no deb.repository
This commit is contained in:
34
src/orders/application/deb.service.ts
Normal file
34
src/orders/application/deb.service.ts
Normal 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user