Alterado end point api/v1/delivery/schedule para mostrar a capacidade e saldo da capacidade com 3 casas decimais e criado peso adicional para mostrar a data de entrega na abertura da venda

This commit is contained in:
eduardoestevao-appsoluti
2025-03-11 17:16:05 -03:00
parent 62f4c767dd
commit 0936c239b9
180 changed files with 18502 additions and 18441 deletions

View File

@@ -1,43 +1,43 @@
/*
https://docs.nestjs.com/controllers#controllers
*/
import { Controller, Get, Param, Query } from '@nestjs/common';
import { CepService } from './cep.service';
import { GoogleService } from 'src/google/google.service';
import { ApiTags } from '@nestjs/swagger';
@ApiTags('Cep')
@Controller('api/v1/cep')
export class CepController {
constructor(
private cepService: CepService,
private googleService: GoogleService,
) {}
@Get('find/:cep')
findCep(@Param('cep') cep: string){
//return this.cepService.findCep(cep);
return this.cepService.findViaCep(cep);
}
@Get('find/viacep/:cep')
findViaCep(@Param('cep') cep: string){
return this.cepService.findViaCep(cep);
}
@Get('geolocation/:cep')
geolocationCep(@Param('cep') cep: string){
return this.cepService.geoLocalicationCep(cep);
}
@Get('google')
async geolocationGoogle(@Query() query){
const address = query['address'];
const addressNumber = query['addressNumber'];
const neighborhood = query['neighborhood'];
const city = query['city'];
const state = query['state'];
return this.googleService.getGeocoder(address, addressNumber, neighborhood, city, state);
}
}
/*
https://docs.nestjs.com/controllers#controllers
*/
import { Controller, Get, Param, Query } from '@nestjs/common';
import { CepService } from './cep.service';
import { GoogleService } from 'src/google/google.service';
import { ApiTags } from '@nestjs/swagger';
@ApiTags('Cep')
@Controller('api/v1/cep')
export class CepController {
constructor(
private cepService: CepService,
private googleService: GoogleService,
) {}
@Get('find/:cep')
findCep(@Param('cep') cep: string){
//return this.cepService.findCep(cep);
return this.cepService.findViaCep(cep);
}
@Get('find/viacep/:cep')
findViaCep(@Param('cep') cep: string){
return this.cepService.findViaCep(cep);
}
@Get('geolocation/:cep')
geolocationCep(@Param('cep') cep: string){
return this.cepService.geoLocalicationCep(cep);
}
@Get('google')
async geolocationGoogle(@Query() query){
const address = query['address'];
const addressNumber = query['addressNumber'];
const neighborhood = query['neighborhood'];
const city = query['city'];
const state = query['state'];
return this.googleService.getGeocoder(address, addressNumber, neighborhood, city, state);
}
}

View File

@@ -1,27 +1,27 @@
import { CepService } from './cep.service';
import { CepController } from './cep.controller';
/*
https://docs.nestjs.com/modules
*/
import { HttpModule, Module } from '@nestjs/common';
import { GoogleService } from 'src/google/google.service';
import { ListsService } from 'src/backoffice/lists/lists.service';
@Module({
imports: [
HttpModule
// HttpModule.register({
// timeout: 5000,
// maxRedirects: 5,
// }),
],
controllers: [
CepController,],
providers: [
CepService,
GoogleService,
ListsService],
})
export class CepModule { }
import { CepService } from './cep.service';
import { CepController } from './cep.controller';
/*
https://docs.nestjs.com/modules
*/
import { HttpModule, Module } from '@nestjs/common';
import { GoogleService } from 'src/google/google.service';
import { ListsService } from 'src/backoffice/lists/lists.service';
@Module({
imports: [
HttpModule
// HttpModule.register({
// timeout: 5000,
// maxRedirects: 5,
// }),
],
controllers: [
CepController,],
providers: [
CepService,
GoogleService,
ListsService],
})
export class CepModule { }

View File

@@ -1,88 +1,88 @@
/* eslint-disable @typescript-eslint/camelcase */
/*
https://docs.nestjs.com/providers#services
*/
import { HttpService, Injectable } from '@nestjs/common';
import { catchError, firstValueFrom, switchMap } from 'rxjs';
import { Cep } from 'src/domain/models/cep.model';
import { GeolocationCep } from 'src/domain/models/geolocation-cep.model';
import { ViaCep } from 'src/domain/models/via-cep.model';
@Injectable()
export class CepService {
constructor(
private readonly httpService: HttpService) { }
async findCep(cep: string): Promise<Cep> {
const url = `http://eduardoestevaogyn-d90e3e3eb6249000.api.findcep.com/v1/cep/${cep}.json`;
const { data } = await firstValueFrom(
this.httpService.get<Cep>(url,
{
headers: {
'Accept': 'application/json',
'Referer': 'EVAB02XJN87NY'
}
}).pipe(
catchError((error) => {
console.log(error);
throw error.response;
}),
)
);
const dataGeoloacation = await this.geoLocalicationCep(cep);
return { ...data, ...dataGeoloacation.location };
}
async findViaCep(cep: string): Promise<Cep> {
const url = `http://viacep.com.br/ws/${cep}/json/`;
const { data } = await firstValueFrom(
this.httpService.get<ViaCep>(url
).pipe(
catchError((error) => {
console.log(error);
throw error.response;
}),
)
);
const dataGeoloacation = { location: { latitude: 0, longitude: 0} };
const dataCep: Cep = {
bairro : data.bairro,
cep: data.cep,
cidade: data.localidade,
codigo_ibge: data.ibge,
complemento: data.complemento,
logradouro: data.logradouro,
nome: null,
status: null,
tipo: null,
uf: data.uf
}
return { ...dataCep, ...dataGeoloacation.location };
}
async geoLocalicationCep(cep: string): Promise<GeolocationCep> {
const url = `http://eduardoestevaogyn-d90e3e3eb6249000.api.findcep.com/v1/geolocation/cep/${cep}`;
const { data } = await firstValueFrom(
this.httpService.get<GeolocationCep>(url,
{
headers: {
'Accept': 'application/json',
'Referer': 'EVAB02XJN87NY'
}
}).pipe(
catchError((error) => {
console.log(error);
throw error.response;
}),
),
);
return data;
}
}
/* eslint-disable @typescript-eslint/camelcase */
/*
https://docs.nestjs.com/providers#services
*/
import { HttpService, Injectable } from '@nestjs/common';
import { catchError, firstValueFrom, switchMap } from 'rxjs';
import { Cep } from 'src/domain/models/cep.model';
import { GeolocationCep } from 'src/domain/models/geolocation-cep.model';
import { ViaCep } from 'src/domain/models/via-cep.model';
@Injectable()
export class CepService {
constructor(
private readonly httpService: HttpService) { }
async findCep(cep: string): Promise<Cep> {
const url = `http://eduardoestevaogyn-d90e3e3eb6249000.api.findcep.com/v1/cep/${cep}.json`;
const { data } = await firstValueFrom(
this.httpService.get<Cep>(url,
{
headers: {
'Accept': 'application/json',
'Referer': 'EVAB02XJN87NY'
}
}).pipe(
catchError((error) => {
console.log(error);
throw error.response;
}),
)
);
const dataGeoloacation = await this.geoLocalicationCep(cep);
return { ...data, ...dataGeoloacation.location };
}
async findViaCep(cep: string): Promise<Cep> {
const url = `http://viacep.com.br/ws/${cep}/json/`;
const { data } = await firstValueFrom(
this.httpService.get<ViaCep>(url
).pipe(
catchError((error) => {
console.log(error);
throw error.response;
}),
)
);
const dataGeoloacation = { location: { latitude: 0, longitude: 0} };
const dataCep: Cep = {
bairro : data.bairro,
cep: data.cep,
cidade: data.localidade,
codigo_ibge: data.ibge,
complemento: data.complemento,
logradouro: data.logradouro,
nome: null,
status: null,
tipo: null,
uf: data.uf
}
return { ...dataCep, ...dataGeoloacation.location };
}
async geoLocalicationCep(cep: string): Promise<GeolocationCep> {
const url = `http://eduardoestevaogyn-d90e3e3eb6249000.api.findcep.com/v1/geolocation/cep/${cep}`;
const { data } = await firstValueFrom(
this.httpService.get<GeolocationCep>(url,
{
headers: {
'Accept': 'application/json',
'Referer': 'EVAB02XJN87NY'
}
}).pipe(
catchError((error) => {
console.log(error);
throw error.response;
}),
),
);
return data;
}
}