diff --git a/src/data-consult/data-consult.repository.ts b/src/data-consult/data-consult.repository.ts index 16fcbe9..ca5e469 100644 --- a/src/data-consult/data-consult.repository.ts +++ b/src/data-consult/data-consult.repository.ts @@ -1,6 +1,5 @@ import { Injectable, Inject } from '@nestjs/common'; import { DataSource } from 'typeorm'; -import { createOracleConfig } from '../core/configs/typeorm.oracle.config'; import { StoreDto } from './dto/store.dto'; import { SellerDto } from './dto/seller.dto'; import { BillingDto } from './dto/billing.dto'; @@ -14,7 +13,7 @@ import { DATA_SOURCE } from '../core/constants'; export class DataConsultRepository { constructor( @Inject(DATA_SOURCE) private readonly dataSource: DataSource, - private readonly configService: ConfigService + private readonly configService: ConfigService, ) {} private async executeQuery(sql: string, params: any[] = []): Promise { @@ -38,10 +37,10 @@ export class DataConsultRepository { ORDER BY TO_NUMBER(PCFILIAL.CODIGO) `; const results = await this.executeQuery(sql); - return results.map(result => new StoreDto(result)); + return results.map((result) => new StoreDto(result)); } -async findSellers(): Promise { + async findSellers(): Promise { const sql = ` SELECT PCUSUARI.CODUSUR as "id", PCUSUARI.NOME as "name" @@ -51,27 +50,28 @@ async findSellers(): Promise { AND (PCUSUARI.BLOQUEIO IS NULL OR PCUSUARI.BLOQUEIO = 'N') `; const results = await this.executeQuery(sql); - return results.map(result => new SellerDto(result)); + return results.map((result) => new SellerDto(result)); } async findBillings(): Promise { const sql = ` - SELECT p.CODCOB, p.COBRANCA FROM PCCOB p + SELECT p.CODCOB as "id", + SYSDATE as "date", + 0 as "total", + p.COBRANCA as "description" + FROM PCCOB p `; const results = await this.executeQuery(sql); - return results.map(result => new BillingDto(result)); + return results.map((result) => new BillingDto(result)); } async findCustomers(filter: string): Promise { - // 1) limpa todos os não-dígitos para buscas exatas const cleanedDigits = filter.replace(/\D/g, ''); - // 2) prepara filtro para busca por nome (LIKE) const likeFilter = `%${filter.toUpperCase().replace(/@/g, '%')}%`; let customers: CustomerDto[] = []; - // --- 1ª tentativa: busca por código do cliente (CODCLI) --- let sql = ` SELECT PCCLIENT.CODCLI AS "id", @@ -84,7 +84,6 @@ async findSellers(): Promise { `; customers = await this.executeQuery(sql, [cleanedDigits]); - // --- 2ª tentativa: busca por CPF/CNPJ (CGCENT) --- if (customers.length === 0) { sql = ` SELECT @@ -99,7 +98,6 @@ async findSellers(): Promise { customers = await this.executeQuery(sql, [cleanedDigits]); } - // --- 3ª tentativa: busca parcial por nome --- if (customers.length === 0) { sql = ` SELECT @@ -114,7 +112,7 @@ async findSellers(): Promise { customers = await this.executeQuery(sql, [likeFilter]); } - return customers.map(row => new CustomerDto(row)); + return customers.map((row) => new CustomerDto(row)); } async findProducts(filter: string): Promise { @@ -125,7 +123,7 @@ async findSellers(): Promise { WHERE PCPRODUT.CODPROD = :filter `; const results = await this.executeQuery(sql, [filter]); - return results.map(result => new ProductDto(result)); + return results.map((result) => new ProductDto(result)); } async findAllProducts(): Promise { @@ -136,12 +134,9 @@ async findSellers(): Promise { WHERE ROWNUM <= 500 `; const results = await this.executeQuery(sql); - return results.map(result => new ProductDto(result)); + return results.map((result) => new ProductDto(result)); } - /** - * Busca todas as transportadoras cadastradas no sistema - */ async findAllCarriers(): Promise { const sql = ` SELECT DISTINCT @@ -157,9 +152,6 @@ async findSellers(): Promise { return await this.executeQuery(sql); } - /** - * Busca as transportadoras por período de data - */ async findCarriersByDate(query: any): Promise { let sql = ` SELECT DISTINCT @@ -178,12 +170,16 @@ async findSellers(): Promise { let paramIndex = 0; if (query.dateIni) { - conditions.push(`AND PCPEDC.DATA >= TO_DATE(:${paramIndex}, 'YYYY-MM-DD')`); + conditions.push( + `AND PCPEDC.DATA >= TO_DATE(:${paramIndex}, 'YYYY-MM-DD')`, + ); parameters.push(query.dateIni); paramIndex++; } if (query.dateEnd) { - conditions.push(`AND PCPEDC.DATA <= TO_DATE(:${paramIndex}, 'YYYY-MM-DD')`); + conditions.push( + `AND PCPEDC.DATA <= TO_DATE(:${paramIndex}, 'YYYY-MM-DD')`, + ); parameters.push(query.dateEnd); paramIndex++; } @@ -193,16 +189,13 @@ async findSellers(): Promise { paramIndex++; } - sql += "\n" + conditions.join("\n"); - sql += "\nGROUP BY PCPEDC.CODFORNECFRETE, PCFORNEC.FORNECEDOR"; - sql += "\nORDER BY PCPEDC.CODFORNECFRETE"; + sql += '\n' + conditions.join('\n'); + sql += '\nGROUP BY PCPEDC.CODFORNECFRETE, PCFORNEC.FORNECEDOR'; + sql += '\nORDER BY PCPEDC.CODFORNECFRETE'; return await this.executeQuery(sql, parameters); } - /** - * Busca as transportadoras de um pedido específico - */ async findOrderCarriers(orderId: number): Promise { const sql = ` SELECT DISTINCT @@ -219,9 +212,6 @@ async findSellers(): Promise { return await this.executeQuery(sql, [orderId]); } - /** - * Busca todas as regiões cadastradas - */ async findRegions(): Promise { const sql = ` SELECT @@ -231,6 +221,6 @@ async findSellers(): Promise { ORDER BY PCREGIAO.NUMREGIAO `; const results = await this.executeQuery(sql); - return results.map(result => new RegionDto(result)); + return results.map((result) => new RegionDto(result)); } -} \ No newline at end of file +}