import { Injectable } from '@nestjs/common'; import { Esventregasporcliente } from 'src/domain/entity/views/esventregasporcliente.entity'; import { Connection, getConnection } from 'typeorm'; import { ResultModel } from '../../domain/models/result.model'; import { Esvretiralojascliente } from '../../domain/entity/views/esventregaslojascliente.entity'; import { EsvRetiraLojas } from '../../domain/entity/views/esvretiralojas.entity'; @Injectable() export class ShippingService { constructor(private connection: Connection) { } async GetShippingsByCustomer(): Promise { const connection = getConnection(); const queryRunner = connection.createQueryRunner(); await queryRunner.connect(); try { /*const user = await this.GetUser(queryRunner); if (user == null) { return new ResultModel(false, 'Não foi possível localizar entregas para este usuário', null, 'Não foi localizado motorista para este usuário.'); }*/ const deliveries = await queryRunner.manager .getRepository(Esventregasporcliente) .createQueryBuilder('ESVENTREGASPORCLIENTE') .select(['cliente as "nomeCliente"' , 'cgcent as "cnpj_cpf"' , 'email as "email"' , 'endereco as "endereco"' , 'numero as "numero"' , 'bairro as "bairro"' , 'complemento as "complemento"' , 'cidade as "cidade"' , 'estado as "uf"' , 'cep as "cep"' , 'qtpedidos as "quantidadePedidos"' , 'qtlojas as "quantidaeLojas"' , 'entrega_concluida as "entregaConcluida"' , 'telefone as "telefoneCliente"' , 'celular as "celularCliente"' , 'codcli as "codigoCliente"']) .where("email = 'eduardoestevao.gyn@gmail.com'") .getRawMany(); return deliveries; } catch (error) { console.log(error); return new ResultModel(false, 'Não foi possível consultar as entregas por cliente.', null, error); } finally { await queryRunner.release(); } } async GetCollectByShop(): Promise { const connection = getConnection(); const queryRunner = connection.createQueryRunner(); await queryRunner.connect(); try { /*const user = await this.GetUser(queryRunner); if (user == null) { return new ResultModel(false, 'Não foi possível localizar entregas para este usuário', null, 'Não foi localizado motorista para este usuário.'); }*/ const deliveries = await queryRunner.manager .getRepository(EsvRetiraLojas) .createQueryBuilder('ESVRETIRALOJAS') .select(['codigo as "codigoLoja"' , 'razaosocial as "razaoSocial"' , 'quantidadepedidos as "quantidadePedidos"' ]) .where("email = 'eduardoestevao.gyn@gmail.com'") .getRawMany(); return deliveries; } catch (error) { console.log(error); return new ResultModel(false, 'Não foi possível consultar as coletas por loja.', null, error); } finally { await queryRunner.release(); } } async GetCollectByCustomer(id: string): Promise { const connection = getConnection(); const queryRunner = connection.createQueryRunner(); await queryRunner.connect(); try { /*const user = await this.GetUser(queryRunner); if (user == null) { return new ResultModel(false, 'Não foi possível localizar entregas para este usuário', null, 'Não foi localizado motorista para este usuário.'); }*/ const deliveries = await queryRunner.manager .getRepository(Esvretiralojascliente) .createQueryBuilder('ESVRETIRALOJASCLIENTE') .select([ 'codfilial as "codigoFilial"' ,'numped as "numeroPedido"' ,'numnota as "numeroNota"' ,'dtfat as "dataFaturamento"' ,'datapedido as "dataPedido"' ,'codcli as "codigoCliente"' ,'cliente as "nomeCliente"' ,'codfilialretira as "codigoLoja"' ,'razaosocial as "nomeLoja"' ,'qtitens as "quantidadeItens"' ,'quantidade as "quantidade"' ]) .where("email = 'eduardoestevao.gyn@gmail.com'") .andWhere("codfilial = :codfilial", {codfilial: id}) .getRawMany(); return deliveries; } catch (error) { console.log(error); return new ResultModel(false, 'Não foi possível consultar as coletas por cliente.', null, error); } finally { await queryRunner.release(); } } }