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