Remove comments and unused import from data-consult repository
This commit is contained in:
@@ -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<T>(sql: string, params: any[] = []): Promise<T> {
|
||||
@@ -38,10 +37,10 @@ export class DataConsultRepository {
|
||||
ORDER BY TO_NUMBER(PCFILIAL.CODIGO)
|
||||
`;
|
||||
const results = await this.executeQuery<StoreDto[]>(sql);
|
||||
return results.map(result => new StoreDto(result));
|
||||
return results.map((result) => new StoreDto(result));
|
||||
}
|
||||
|
||||
async findSellers(): Promise<SellerDto[]> {
|
||||
async findSellers(): Promise<SellerDto[]> {
|
||||
const sql = `
|
||||
SELECT PCUSUARI.CODUSUR as "id",
|
||||
PCUSUARI.NOME as "name"
|
||||
@@ -51,27 +50,28 @@ async findSellers(): Promise<SellerDto[]> {
|
||||
AND (PCUSUARI.BLOQUEIO IS NULL OR PCUSUARI.BLOQUEIO = 'N')
|
||||
`;
|
||||
const results = await this.executeQuery<SellerDto[]>(sql);
|
||||
return results.map(result => new SellerDto(result));
|
||||
return results.map((result) => new SellerDto(result));
|
||||
}
|
||||
|
||||
async findBillings(): Promise<BillingDto[]> {
|
||||
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<BillingDto[]>(sql);
|
||||
return results.map(result => new BillingDto(result));
|
||||
return results.map((result) => new BillingDto(result));
|
||||
}
|
||||
|
||||
async findCustomers(filter: string): Promise<CustomerDto[]> {
|
||||
// 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<SellerDto[]> {
|
||||
`;
|
||||
customers = await this.executeQuery<CustomerDto[]>(sql, [cleanedDigits]);
|
||||
|
||||
// --- 2ª tentativa: busca por CPF/CNPJ (CGCENT) ---
|
||||
if (customers.length === 0) {
|
||||
sql = `
|
||||
SELECT
|
||||
@@ -99,7 +98,6 @@ async findSellers(): Promise<SellerDto[]> {
|
||||
customers = await this.executeQuery<CustomerDto[]>(sql, [cleanedDigits]);
|
||||
}
|
||||
|
||||
// --- 3ª tentativa: busca parcial por nome ---
|
||||
if (customers.length === 0) {
|
||||
sql = `
|
||||
SELECT
|
||||
@@ -114,7 +112,7 @@ async findSellers(): Promise<SellerDto[]> {
|
||||
customers = await this.executeQuery<CustomerDto[]>(sql, [likeFilter]);
|
||||
}
|
||||
|
||||
return customers.map(row => new CustomerDto(row));
|
||||
return customers.map((row) => new CustomerDto(row));
|
||||
}
|
||||
|
||||
async findProducts(filter: string): Promise<ProductDto[]> {
|
||||
@@ -125,7 +123,7 @@ async findSellers(): Promise<SellerDto[]> {
|
||||
WHERE PCPRODUT.CODPROD = :filter
|
||||
`;
|
||||
const results = await this.executeQuery<ProductDto[]>(sql, [filter]);
|
||||
return results.map(result => new ProductDto(result));
|
||||
return results.map((result) => new ProductDto(result));
|
||||
}
|
||||
|
||||
async findAllProducts(): Promise<ProductDto[]> {
|
||||
@@ -136,12 +134,9 @@ async findSellers(): Promise<SellerDto[]> {
|
||||
WHERE ROWNUM <= 500
|
||||
`;
|
||||
const results = await this.executeQuery<ProductDto[]>(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<any[]> {
|
||||
const sql = `
|
||||
SELECT DISTINCT
|
||||
@@ -157,9 +152,6 @@ async findSellers(): Promise<SellerDto[]> {
|
||||
return await this.executeQuery<any[]>(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Busca as transportadoras por período de data
|
||||
*/
|
||||
async findCarriersByDate(query: any): Promise<any[]> {
|
||||
let sql = `
|
||||
SELECT DISTINCT
|
||||
@@ -178,12 +170,16 @@ async findSellers(): Promise<SellerDto[]> {
|
||||
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<SellerDto[]> {
|
||||
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<any[]>(sql, parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Busca as transportadoras de um pedido específico
|
||||
*/
|
||||
async findOrderCarriers(orderId: number): Promise<any[]> {
|
||||
const sql = `
|
||||
SELECT DISTINCT
|
||||
@@ -219,9 +212,6 @@ async findSellers(): Promise<SellerDto[]> {
|
||||
return await this.executeQuery<any[]>(sql, [orderId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Busca todas as regiões cadastradas
|
||||
*/
|
||||
async findRegions(): Promise<RegionDto[]> {
|
||||
const sql = `
|
||||
SELECT
|
||||
@@ -231,6 +221,6 @@ async findSellers(): Promise<SellerDto[]> {
|
||||
ORDER BY PCREGIAO.NUMREGIAO
|
||||
`;
|
||||
const results = await this.executeQuery<RegionDto[]>(sql);
|
||||
return results.map(result => new RegionDto(result));
|
||||
return results.map((result) => new RegionDto(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user