Ajuste conexao oracle & postgres
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { typeOrmConfig } from '../core/configs/typeorm.config';
|
||||
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';
|
||||
import { CustomerDto } from './dto/customer.dto';
|
||||
import { ProductDto } from './dto/product.dto';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
@Injectable()
|
||||
export class DataConsultRepository {
|
||||
private readonly dataSource: DataSource;
|
||||
|
||||
constructor() {
|
||||
this.dataSource = new DataSource(typeOrmConfig);
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
this.dataSource = new DataSource(createOracleConfig(configService));
|
||||
this.dataSource.initialize();
|
||||
}
|
||||
|
||||
@@ -63,56 +64,64 @@ export class DataConsultRepository {
|
||||
}
|
||||
|
||||
async findCustomers(filter: string): Promise<CustomerDto[]> {
|
||||
if (!filter || typeof filter !== 'string') return [];
|
||||
|
||||
const cleanedNumeric = filter.replace(/[^\d]/g, '');
|
||||
const likeFilter = filter.toUpperCase().replace('@', '%') + '%';
|
||||
|
||||
const queries = [
|
||||
// Busca por código (apenas números)
|
||||
{
|
||||
sql: `
|
||||
SELECT PCCLIENT.CODCLI as "id",
|
||||
PCCLIENT.CODCLI || ' - ' || PCCLIENT.CLIENTE ||
|
||||
' ( ' || REGEXP_REPLACE(PCCLIENT.CGCENT, '[^0-9]', '') || ' )' as "name"
|
||||
FROM PCCLIENT
|
||||
WHERE PCCLIENT.CODCLI = REGEXP_REPLACE(?, '[^0-9]', '')
|
||||
WHERE PCCLIENT.CODCLI = :1
|
||||
ORDER BY PCCLIENT.CLIENTE
|
||||
`,
|
||||
params: [filter],
|
||||
params: [cleanedNumeric],
|
||||
},
|
||||
// Busca por CNPJ/CPF limpo
|
||||
{
|
||||
sql: `
|
||||
SELECT PCCLIENT.CODCLI as "id",
|
||||
PCCLIENT.CODCLI || ' - ' || PCCLIENT.CLIENTE ||
|
||||
' ( ' || REGEXP_REPLACE(PCCLIENT.CGCENT, '[^0-9]', '') || ' )' as "name"
|
||||
FROM PCCLIENT
|
||||
WHERE REGEXP_REPLACE(PCCLIENT.CGCENT, '[^0-9]', '') = REGEXP_REPLACE(?, '[^0-9]', '')
|
||||
WHERE REGEXP_REPLACE(PCCLIENT.CGCENT, '[^0-9]', '') = :1
|
||||
ORDER BY PCCLIENT.CLIENTE
|
||||
`,
|
||||
params: [filter],
|
||||
params: [cleanedNumeric],
|
||||
},
|
||||
// Busca por nome do cliente
|
||||
{
|
||||
sql: `
|
||||
SELECT PCCLIENT.CODCLI as "id",
|
||||
PCCLIENT.CODCLI || ' - ' || PCCLIENT.CLIENTE ||
|
||||
' ( ' || REGEXP_REPLACE(PCCLIENT.CGCENT, '[^0-9]', '') || ' )' as "name"
|
||||
FROM PCCLIENT
|
||||
WHERE PCCLIENT.CLIENTE LIKE ?
|
||||
WHERE UPPER(PCCLIENT.CLIENTE) LIKE :1
|
||||
ORDER BY PCCLIENT.CLIENTE
|
||||
`,
|
||||
params: [filter.toUpperCase().replace('@', '%') + '%'],
|
||||
params: [likeFilter],
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
for (const { sql, params } of queries) {
|
||||
const result = await this.executeQuery<CustomerDto[]>(sql, params);
|
||||
if (result.length > 0) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
async findProducts(filter: string): Promise<ProductDto[]> {
|
||||
const cleanFilter = filter.replace(/[^\d]/g, '');
|
||||
const cleanedFilter = filter.replace(/[^\d]/g, ''); // apenas números
|
||||
const likeFilter = filter + '%';
|
||||
const codAux = filter.replace(/[^\d]/g, '');
|
||||
|
||||
const queries = [
|
||||
{
|
||||
@@ -124,7 +133,7 @@ export class DataConsultRepository {
|
||||
WHERE PCPRODUT.CODPROD = ?
|
||||
ORDER BY PCPRODUT.DESCRICAO
|
||||
`,
|
||||
params: [cleanFilter],
|
||||
params: [cleanedFilter],
|
||||
},
|
||||
{
|
||||
sql: `
|
||||
@@ -135,7 +144,7 @@ export class DataConsultRepository {
|
||||
WHERE PCPRODUT.CODAUXILIAR = ?
|
||||
ORDER BY PCPRODUT.DESCRICAO
|
||||
`,
|
||||
params: [codAux],
|
||||
params: [cleanedFilter],
|
||||
},
|
||||
{
|
||||
sql: `
|
||||
|
||||
Reference in New Issue
Block a user