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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 { }
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
/*
|
||||
https://docs.nestjs.com/controllers#controllers
|
||||
*/
|
||||
|
||||
import { Controller, Get, Param, Query } from '@nestjs/common';
|
||||
import { DashboardService } from './dashboard.service';
|
||||
|
||||
@Controller('api/v1/dashboard')
|
||||
export class DashboardController {
|
||||
|
||||
constructor(private dashboardService: DashboardService){}
|
||||
|
||||
@Get('sale')
|
||||
getSale() {
|
||||
return this.dashboardService.dashboarSale();
|
||||
}
|
||||
|
||||
@Get('sale/store')
|
||||
getSaleSellers(@Query() query) {
|
||||
let supervisorIds: string;
|
||||
if (query['ids'] != null) {
|
||||
supervisorIds = query['ids'];
|
||||
}
|
||||
return this.dashboardService.dashboardSeller(null, supervisorIds);
|
||||
}
|
||||
|
||||
|
||||
@Get('sale/company')
|
||||
getSaleCompany(@Query() query) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
let supervisorIds: string;
|
||||
if (query['ids'] != null) {
|
||||
supervisorIds = query['ids'];
|
||||
}
|
||||
return this.dashboardService.dashboardCompany();
|
||||
}
|
||||
|
||||
|
||||
@Get('sale/:supervisorId')
|
||||
getSaleSeller(@Param('supervisorId') supervisorId: number) {
|
||||
return this.dashboardService.dashboardSeller(supervisorId, null);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
https://docs.nestjs.com/controllers#controllers
|
||||
*/
|
||||
|
||||
import { Controller, Get, Param, Query } from '@nestjs/common';
|
||||
import { DashboardService } from './dashboard.service';
|
||||
|
||||
@Controller('api/v1/dashboard')
|
||||
export class DashboardController {
|
||||
|
||||
constructor(private dashboardService: DashboardService){}
|
||||
|
||||
@Get('sale')
|
||||
getSale() {
|
||||
return this.dashboardService.dashboarSale();
|
||||
}
|
||||
|
||||
@Get('sale/store')
|
||||
getSaleSellers(@Query() query) {
|
||||
let supervisorIds: string;
|
||||
if (query['ids'] != null) {
|
||||
supervisorIds = query['ids'];
|
||||
}
|
||||
return this.dashboardService.dashboardSeller(null, supervisorIds);
|
||||
}
|
||||
|
||||
|
||||
@Get('sale/company')
|
||||
getSaleCompany(@Query() query) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
let supervisorIds: string;
|
||||
if (query['ids'] != null) {
|
||||
supervisorIds = query['ids'];
|
||||
}
|
||||
return this.dashboardService.dashboardCompany();
|
||||
}
|
||||
|
||||
|
||||
@Get('sale/:supervisorId')
|
||||
getSaleSeller(@Param('supervisorId') supervisorId: number) {
|
||||
return this.dashboardService.dashboardSeller(supervisorId, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { DashboardService } from './dashboard.service';
|
||||
import { DashboardController } from './dashboard.controller';
|
||||
/*
|
||||
https://docs.nestjs.com/modules
|
||||
*/
|
||||
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [
|
||||
DashboardController,],
|
||||
providers: [
|
||||
DashboardService,],
|
||||
})
|
||||
export class DashboardModule { }
|
||||
import { DashboardService } from './dashboard.service';
|
||||
import { DashboardController } from './dashboard.controller';
|
||||
/*
|
||||
https://docs.nestjs.com/modules
|
||||
*/
|
||||
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [
|
||||
DashboardController,],
|
||||
providers: [
|
||||
DashboardService,],
|
||||
})
|
||||
export class DashboardModule { }
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,154 +1,154 @@
|
||||
/*
|
||||
https://docs.nestjs.com/controllers#controllers
|
||||
*/
|
||||
|
||||
import { Body, Controller, Get, HttpException, HttpStatus, Post, Req } from '@nestjs/common';
|
||||
import { Param } from '@nestjs/common/decorators';
|
||||
import { Cart } from 'src/domain/models/cart.model';
|
||||
import { ResultModel } from 'src/domain/models/result.model';
|
||||
import { OrderService } from './order.service';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Order')
|
||||
@Controller('api/v1/order')
|
||||
export class OrderController {
|
||||
constructor(private readonly orderService: OrderService) { }
|
||||
|
||||
@Get('list')
|
||||
async getOrder(@Req() request) {
|
||||
try {
|
||||
let store = '';
|
||||
let initialDate = new Date();
|
||||
let finalDate = new Date();
|
||||
let name: string;
|
||||
let document: string;
|
||||
let sellerId = 0;
|
||||
let idOrder = '';
|
||||
if (request.query['x-store'])
|
||||
store = request.query['x-store'];
|
||||
if (request.query['initialDate']){
|
||||
initialDate = request.query['initialDate'];
|
||||
}
|
||||
if (request.query['finalDate']){
|
||||
finalDate = request.query['finalDate'] = finalDate;
|
||||
}
|
||||
if (request.query['document'])
|
||||
document = request.query['document'];
|
||||
if (request.query['name'])
|
||||
name = request.query['name'];
|
||||
if (request.query['sellerId'])
|
||||
sellerId = request.query['sellerId'];
|
||||
if (request.query['idOrder'])
|
||||
idOrder = request.query['idOrder'];
|
||||
const result = await this.orderService.getOrders(store, initialDate, finalDate, document, name, sellerId, idOrder);
|
||||
return result;
|
||||
} catch (err) {
|
||||
throw new HttpException(new ResultModel(false, err.errors.message, {}, err),
|
||||
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Get('cart')
|
||||
async getCart(@Req() request) {
|
||||
console.log('consultando pedido de venda');
|
||||
let orderId = 0;
|
||||
const query = request.query;
|
||||
if (query.orderId) {
|
||||
orderId = query.orderId;
|
||||
}
|
||||
if (orderId == 0) {
|
||||
throw new HttpException('Informe um número do pedido de venda para realizar a pesquisa.', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return await this.orderService.getCartId(orderId);
|
||||
}
|
||||
|
||||
@Get('productsTax')
|
||||
async getProductsWithoutTax(@Req() request) {
|
||||
let cartId = '';
|
||||
let customerId = 0;
|
||||
const query = request.query;
|
||||
if (query.cartId) {
|
||||
cartId = query.cartId;
|
||||
}
|
||||
if (query.customerId) {
|
||||
customerId = query.customerId;
|
||||
}
|
||||
return await this.orderService.productsWithoutTax(cartId, customerId);
|
||||
}
|
||||
|
||||
@Get('orderretiraposterior')
|
||||
async getOrdersRetiraPosterior() {
|
||||
return await this.orderService.OrderRetiraPosterior();
|
||||
}
|
||||
|
||||
@Get('itens/:id')
|
||||
async getItensOrder(@Param('id') orderId: number) {
|
||||
console.log('consultando pedido de venda');
|
||||
if (orderId == 0) {
|
||||
throw new HttpException('Informe um número do pedido de venda para realizar a pesquisa.', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return await this.orderService.getItensOrder(orderId);
|
||||
}
|
||||
|
||||
|
||||
@Post('create')
|
||||
async createOrder(@Body() cart: Cart) {
|
||||
console.log("cart: " + JSON.stringify(cart));
|
||||
try {
|
||||
const result = await this.orderService.create(cart);
|
||||
return new ResultModel(true, null, result, null);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw new HttpException(new ResultModel(false, err.response, {}, err),
|
||||
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get('products-order')
|
||||
async getProductsOrder(@Req() request) {
|
||||
try {
|
||||
let store = '';
|
||||
let initialDate = new Date();
|
||||
let finalDate = new Date();
|
||||
let name: string;
|
||||
let document: string;
|
||||
let sellerId = 0;
|
||||
let idOrder = '';
|
||||
let typeFilterProduct = '';
|
||||
let productText = '';
|
||||
if (request.query['x-store'])
|
||||
store = request.query['x-store'];
|
||||
|
||||
if (request.query['initialDate']){
|
||||
initialDate = request.query['initialDate'];
|
||||
}
|
||||
if (request.query['finalDate']){
|
||||
finalDate = request.query['finalDate'] = finalDate;
|
||||
}
|
||||
if (request.query['document'])
|
||||
document = request.query['document'];
|
||||
if (request.query['name'])
|
||||
name = request.query['name'];
|
||||
if (request.query['sellerId'])
|
||||
sellerId = request.query['sellerId'];
|
||||
if (request.query['idOrder'])
|
||||
idOrder = request.query['idOrder'];
|
||||
if (request.query['typeFilterProduct'])
|
||||
typeFilterProduct = request.query['typeFilterProduct'];
|
||||
if (request.query['productText'])
|
||||
productText = request.query['productText'];
|
||||
|
||||
const result = await this.orderService
|
||||
.getProductsOrder(store, initialDate, finalDate,
|
||||
document, name, sellerId, idOrder,
|
||||
typeFilterProduct,
|
||||
productText );
|
||||
return result;
|
||||
} catch (err) {
|
||||
throw new HttpException(new ResultModel(false, err.errors.message, {}, err),
|
||||
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
https://docs.nestjs.com/controllers#controllers
|
||||
*/
|
||||
|
||||
import { Body, Controller, Get, HttpException, HttpStatus, Post, Req } from '@nestjs/common';
|
||||
import { Param } from '@nestjs/common/decorators';
|
||||
import { Cart } from 'src/domain/models/cart.model';
|
||||
import { ResultModel } from 'src/domain/models/result.model';
|
||||
import { OrderService } from './order.service';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Order')
|
||||
@Controller('api/v1/order')
|
||||
export class OrderController {
|
||||
constructor(private readonly orderService: OrderService) { }
|
||||
|
||||
@Get('list')
|
||||
async getOrder(@Req() request) {
|
||||
try {
|
||||
let store = '';
|
||||
let initialDate = new Date();
|
||||
let finalDate = new Date();
|
||||
let name: string;
|
||||
let document: string;
|
||||
let sellerId = 0;
|
||||
let idOrder = '';
|
||||
if (request.query['x-store'])
|
||||
store = request.query['x-store'];
|
||||
if (request.query['initialDate']){
|
||||
initialDate = request.query['initialDate'];
|
||||
}
|
||||
if (request.query['finalDate']){
|
||||
finalDate = request.query['finalDate'] = finalDate;
|
||||
}
|
||||
if (request.query['document'])
|
||||
document = request.query['document'];
|
||||
if (request.query['name'])
|
||||
name = request.query['name'];
|
||||
if (request.query['sellerId'])
|
||||
sellerId = request.query['sellerId'];
|
||||
if (request.query['idOrder'])
|
||||
idOrder = request.query['idOrder'];
|
||||
const result = await this.orderService.getOrders(store, initialDate, finalDate, document, name, sellerId, idOrder);
|
||||
return result;
|
||||
} catch (err) {
|
||||
throw new HttpException(new ResultModel(false, err.errors.message, {}, err),
|
||||
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Get('cart')
|
||||
async getCart(@Req() request) {
|
||||
console.log('consultando pedido de venda');
|
||||
let orderId = 0;
|
||||
const query = request.query;
|
||||
if (query.orderId) {
|
||||
orderId = query.orderId;
|
||||
}
|
||||
if (orderId == 0) {
|
||||
throw new HttpException('Informe um número do pedido de venda para realizar a pesquisa.', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return await this.orderService.getCartId(orderId);
|
||||
}
|
||||
|
||||
@Get('productsTax')
|
||||
async getProductsWithoutTax(@Req() request) {
|
||||
let cartId = '';
|
||||
let customerId = 0;
|
||||
const query = request.query;
|
||||
if (query.cartId) {
|
||||
cartId = query.cartId;
|
||||
}
|
||||
if (query.customerId) {
|
||||
customerId = query.customerId;
|
||||
}
|
||||
return await this.orderService.productsWithoutTax(cartId, customerId);
|
||||
}
|
||||
|
||||
@Get('orderretiraposterior')
|
||||
async getOrdersRetiraPosterior() {
|
||||
return await this.orderService.OrderRetiraPosterior();
|
||||
}
|
||||
|
||||
@Get('itens/:id')
|
||||
async getItensOrder(@Param('id') orderId: number) {
|
||||
console.log('consultando pedido de venda');
|
||||
if (orderId == 0) {
|
||||
throw new HttpException('Informe um número do pedido de venda para realizar a pesquisa.', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return await this.orderService.getItensOrder(orderId);
|
||||
}
|
||||
|
||||
|
||||
@Post('create')
|
||||
async createOrder(@Body() cart: Cart) {
|
||||
console.log("cart: " + JSON.stringify(cart));
|
||||
try {
|
||||
const result = await this.orderService.create(cart);
|
||||
return new ResultModel(true, null, result, null);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw new HttpException(new ResultModel(false, err.response, {}, err),
|
||||
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get('products-order')
|
||||
async getProductsOrder(@Req() request) {
|
||||
try {
|
||||
let store = '';
|
||||
let initialDate = new Date();
|
||||
let finalDate = new Date();
|
||||
let name: string;
|
||||
let document: string;
|
||||
let sellerId = 0;
|
||||
let idOrder = '';
|
||||
let typeFilterProduct = '';
|
||||
let productText = '';
|
||||
if (request.query['x-store'])
|
||||
store = request.query['x-store'];
|
||||
|
||||
if (request.query['initialDate']){
|
||||
initialDate = request.query['initialDate'];
|
||||
}
|
||||
if (request.query['finalDate']){
|
||||
finalDate = request.query['finalDate'] = finalDate;
|
||||
}
|
||||
if (request.query['document'])
|
||||
document = request.query['document'];
|
||||
if (request.query['name'])
|
||||
name = request.query['name'];
|
||||
if (request.query['sellerId'])
|
||||
sellerId = request.query['sellerId'];
|
||||
if (request.query['idOrder'])
|
||||
idOrder = request.query['idOrder'];
|
||||
if (request.query['typeFilterProduct'])
|
||||
typeFilterProduct = request.query['typeFilterProduct'];
|
||||
if (request.query['productText'])
|
||||
productText = request.query['productText'];
|
||||
|
||||
const result = await this.orderService
|
||||
.getProductsOrder(store, initialDate, finalDate,
|
||||
document, name, sellerId, idOrder,
|
||||
typeFilterProduct,
|
||||
productText );
|
||||
return result;
|
||||
} catch (err) {
|
||||
throw new HttpException(new ResultModel(false, err.errors.message, {}, err),
|
||||
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
import { OrderController } from './order.controller';
|
||||
/*
|
||||
https://docs.nestjs.com/modules
|
||||
*/
|
||||
|
||||
import { HttpModule, Module } from '@nestjs/common';
|
||||
import { OrderService } from './order.service';
|
||||
import { ListsService } from 'src/backoffice/lists/lists.service';
|
||||
import { CustomerService } from '../customer/customer.service';
|
||||
import { AddressCustomerService } from '../address-customer/address-customer.service';
|
||||
import { ShoppingService } from '../shopping/shopping.service';
|
||||
import { UserService } from 'src/Auth/services/user.service';
|
||||
|
||||
@Module({
|
||||
imports: [HttpModule],
|
||||
controllers: [
|
||||
OrderController,
|
||||
OrderController,],
|
||||
providers: [
|
||||
OrderService,
|
||||
OrderService,
|
||||
ListsService,
|
||||
CustomerService,
|
||||
AddressCustomerService,
|
||||
ShoppingService,
|
||||
UserService,
|
||||
],
|
||||
exports: [OrderService]
|
||||
})
|
||||
export class OrderModule { }
|
||||
import { OrderController } from './order.controller';
|
||||
/*
|
||||
https://docs.nestjs.com/modules
|
||||
*/
|
||||
|
||||
import { HttpModule, Module } from '@nestjs/common';
|
||||
import { OrderService } from './order.service';
|
||||
import { ListsService } from 'src/backoffice/lists/lists.service';
|
||||
import { CustomerService } from '../customer/customer.service';
|
||||
import { AddressCustomerService } from '../address-customer/address-customer.service';
|
||||
import { ShoppingService } from '../shopping/shopping.service';
|
||||
import { UserService } from 'src/Auth/services/user.service';
|
||||
|
||||
@Module({
|
||||
imports: [HttpModule],
|
||||
controllers: [
|
||||
OrderController,
|
||||
OrderController,],
|
||||
providers: [
|
||||
OrderService,
|
||||
OrderService,
|
||||
ListsService,
|
||||
CustomerService,
|
||||
AddressCustomerService,
|
||||
ShoppingService,
|
||||
UserService,
|
||||
],
|
||||
exports: [OrderService]
|
||||
})
|
||||
export class OrderModule { }
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
/*
|
||||
https://docs.nestjs.com/modules
|
||||
*/
|
||||
|
||||
import { HttpModule, Module } from '@nestjs/common';
|
||||
import { OrderModule } from 'src/sales/order/order.module';
|
||||
import { PixSantanderController } from './santander/pix-santander.controller';
|
||||
import { PixSantanderService } from './santander/pix-santander.service';
|
||||
|
||||
@Module({
|
||||
imports: [HttpModule, OrderModule],
|
||||
controllers: [PixSantanderController],
|
||||
providers: [PixSantanderService],
|
||||
})
|
||||
export class PaymentPixModule {}
|
||||
/*
|
||||
https://docs.nestjs.com/modules
|
||||
*/
|
||||
|
||||
import { HttpModule, Module } from '@nestjs/common';
|
||||
import { OrderModule } from 'src/sales/order/order.module';
|
||||
import { PixSantanderController } from './santander/pix-santander.controller';
|
||||
import { PixSantanderService } from './santander/pix-santander.service';
|
||||
|
||||
@Module({
|
||||
imports: [HttpModule, OrderModule],
|
||||
controllers: [PixSantanderController],
|
||||
providers: [PixSantanderService],
|
||||
})
|
||||
export class PaymentPixModule {}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
export interface SantanderPixAuthToken {
|
||||
refreshUrl: string;
|
||||
token_type: string;
|
||||
client_id: string;
|
||||
access_token: string;
|
||||
refresh_token: string;
|
||||
scopes: string;
|
||||
expires_in: string;
|
||||
}
|
||||
|
||||
export interface SantanderPixAuthToken {
|
||||
refreshUrl: string;
|
||||
token_type: string;
|
||||
client_id: string;
|
||||
access_token: string;
|
||||
refresh_token: string;
|
||||
scopes: string;
|
||||
expires_in: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,72 +1,72 @@
|
||||
export interface Paginacao {
|
||||
paginaAtual: number;
|
||||
itensPorPagina: number;
|
||||
quantidadeDePaginas: number;
|
||||
quantidadeTotalDeItens: number;
|
||||
}
|
||||
|
||||
export interface Parametros {
|
||||
inicio: Date;
|
||||
fim: Date;
|
||||
paginacao: Paginacao;
|
||||
}
|
||||
|
||||
export interface Calendario {
|
||||
criacao: Date;
|
||||
expiracao: string;
|
||||
}
|
||||
|
||||
export interface Devedor {
|
||||
cnpj: string;
|
||||
nome: string;
|
||||
}
|
||||
|
||||
export interface Valor {
|
||||
original: string;
|
||||
}
|
||||
|
||||
export interface Pagador {
|
||||
cnpj: string;
|
||||
nome: string;
|
||||
}
|
||||
|
||||
export interface Horario {
|
||||
solicitacao: Date;
|
||||
}
|
||||
|
||||
export interface Devolucao {
|
||||
id: string;
|
||||
rtrId: string;
|
||||
valor: string;
|
||||
horario: Horario;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface Pix {
|
||||
endToEndId: string;
|
||||
txid: string;
|
||||
valor: string;
|
||||
horario: Date;
|
||||
pagador: Pagador;
|
||||
infoPagador: string;
|
||||
devolucoes: Devolucao[];
|
||||
}
|
||||
|
||||
export interface Cob {
|
||||
status: string;
|
||||
calendario: Calendario;
|
||||
location: string;
|
||||
txid: string;
|
||||
revisao: number;
|
||||
devedor: Devedor;
|
||||
valor: Valor;
|
||||
chave: string;
|
||||
solicitacaoPagador: string;
|
||||
pix: Pix[];
|
||||
}
|
||||
|
||||
export interface SantanderCreatePix {
|
||||
parametros: Parametros;
|
||||
cobs: Cob[];
|
||||
}
|
||||
|
||||
export interface Paginacao {
|
||||
paginaAtual: number;
|
||||
itensPorPagina: number;
|
||||
quantidadeDePaginas: number;
|
||||
quantidadeTotalDeItens: number;
|
||||
}
|
||||
|
||||
export interface Parametros {
|
||||
inicio: Date;
|
||||
fim: Date;
|
||||
paginacao: Paginacao;
|
||||
}
|
||||
|
||||
export interface Calendario {
|
||||
criacao: Date;
|
||||
expiracao: string;
|
||||
}
|
||||
|
||||
export interface Devedor {
|
||||
cnpj: string;
|
||||
nome: string;
|
||||
}
|
||||
|
||||
export interface Valor {
|
||||
original: string;
|
||||
}
|
||||
|
||||
export interface Pagador {
|
||||
cnpj: string;
|
||||
nome: string;
|
||||
}
|
||||
|
||||
export interface Horario {
|
||||
solicitacao: Date;
|
||||
}
|
||||
|
||||
export interface Devolucao {
|
||||
id: string;
|
||||
rtrId: string;
|
||||
valor: string;
|
||||
horario: Horario;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface Pix {
|
||||
endToEndId: string;
|
||||
txid: string;
|
||||
valor: string;
|
||||
horario: Date;
|
||||
pagador: Pagador;
|
||||
infoPagador: string;
|
||||
devolucoes: Devolucao[];
|
||||
}
|
||||
|
||||
export interface Cob {
|
||||
status: string;
|
||||
calendario: Calendario;
|
||||
location: string;
|
||||
txid: string;
|
||||
revisao: number;
|
||||
devedor: Devedor;
|
||||
valor: Valor;
|
||||
chave: string;
|
||||
solicitacaoPagador: string;
|
||||
pix: Pix[];
|
||||
}
|
||||
|
||||
export interface SantanderCreatePix {
|
||||
parametros: Parametros;
|
||||
cobs: Cob[];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
export interface Calendario {
|
||||
dataDeVencimento: string;
|
||||
validadeAposVencimento: number;
|
||||
}
|
||||
|
||||
export interface Devedor {
|
||||
logradouro: string;
|
||||
cidade: string;
|
||||
uf: string;
|
||||
cep: string;
|
||||
cpf: string;
|
||||
nome: string;
|
||||
}
|
||||
|
||||
export interface Multa {
|
||||
modalidade: string;
|
||||
valorPerc: number;
|
||||
}
|
||||
|
||||
export interface Juros {
|
||||
modalidade: string;
|
||||
valorPerc: number;
|
||||
}
|
||||
|
||||
export interface DescontoDataFixa {
|
||||
data: string;
|
||||
valorPerc: string;
|
||||
}
|
||||
|
||||
export interface Desconto {
|
||||
modalidade: string;
|
||||
descontoDataFixa: DescontoDataFixa[];
|
||||
}
|
||||
|
||||
export interface Valor {
|
||||
original: number;
|
||||
multa: Multa;
|
||||
juros: Juros;
|
||||
desconto: Desconto;
|
||||
}
|
||||
|
||||
export interface SantanderCreateCob {
|
||||
calendario: Calendario;
|
||||
devedor: Devedor;
|
||||
valor: Valor;
|
||||
chave: string;
|
||||
solicitacaoPagador: string;
|
||||
}
|
||||
|
||||
export interface Calendario {
|
||||
dataDeVencimento: string;
|
||||
validadeAposVencimento: number;
|
||||
}
|
||||
|
||||
export interface Devedor {
|
||||
logradouro: string;
|
||||
cidade: string;
|
||||
uf: string;
|
||||
cep: string;
|
||||
cpf: string;
|
||||
nome: string;
|
||||
}
|
||||
|
||||
export interface Multa {
|
||||
modalidade: string;
|
||||
valorPerc: number;
|
||||
}
|
||||
|
||||
export interface Juros {
|
||||
modalidade: string;
|
||||
valorPerc: number;
|
||||
}
|
||||
|
||||
export interface DescontoDataFixa {
|
||||
data: string;
|
||||
valorPerc: string;
|
||||
}
|
||||
|
||||
export interface Desconto {
|
||||
modalidade: string;
|
||||
descontoDataFixa: DescontoDataFixa[];
|
||||
}
|
||||
|
||||
export interface Valor {
|
||||
original: number;
|
||||
multa: Multa;
|
||||
juros: Juros;
|
||||
desconto: Desconto;
|
||||
}
|
||||
|
||||
export interface SantanderCreateCob {
|
||||
calendario: Calendario;
|
||||
devedor: Devedor;
|
||||
valor: Valor;
|
||||
chave: string;
|
||||
solicitacaoPagador: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export interface OrderPayment {
|
||||
orderId: number,
|
||||
customerId: number,
|
||||
amount: number,
|
||||
export interface OrderPayment {
|
||||
orderId: number,
|
||||
customerId: number,
|
||||
amount: number,
|
||||
}
|
||||
@@ -1,22 +1,22 @@
|
||||
/*
|
||||
https://docs.nestjs.com/controllers#controllers
|
||||
*/
|
||||
|
||||
import { Body, Controller, Post } from '@nestjs/common';
|
||||
import { OrderPayment } from './models/order-payment.model';
|
||||
import { PixSantanderService } from './pix-santander.service';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Pix-Santander')
|
||||
@Controller('api/v1/payment/pix/santander')
|
||||
export class PixSantanderController {
|
||||
constructor (private pixSantanderService: PixSantanderService){}
|
||||
|
||||
@Post('create')
|
||||
async create(@Body() orderPayment: OrderPayment ){
|
||||
|
||||
return this.pixSantanderService.create(orderPayment);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
/*
|
||||
https://docs.nestjs.com/controllers#controllers
|
||||
*/
|
||||
|
||||
import { Body, Controller, Post } from '@nestjs/common';
|
||||
import { OrderPayment } from './models/order-payment.model';
|
||||
import { PixSantanderService } from './pix-santander.service';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Pix-Santander')
|
||||
@Controller('api/v1/payment/pix/santander')
|
||||
export class PixSantanderController {
|
||||
constructor (private pixSantanderService: PixSantanderService){}
|
||||
|
||||
@Post('create')
|
||||
async create(@Body() orderPayment: OrderPayment ){
|
||||
|
||||
return this.pixSantanderService.create(orderPayment);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,159 +1,159 @@
|
||||
|
||||
/*
|
||||
https://docs.nestjs.com/providers#services
|
||||
*/
|
||||
|
||||
import { HttpService, Injectable, HttpException } from '@nestjs/common';
|
||||
import QueryString = require('qs');
|
||||
import { map, catchError, lastValueFrom } from 'rxjs';
|
||||
import { HttpStatus } from '@nestjs/common/enums';
|
||||
import { SantanderPixAuthToken } from './models/auth-token.model';
|
||||
import { Calendario, Devedor, SantanderCreateCob, Valor } from './models/create-cob.model';
|
||||
import { OrderService } from 'src/sales/order/order.service';
|
||||
import { OrderPayment } from './models/order-payment.model';
|
||||
import { SantanderCreatePix } from './models/cob-pix.model';
|
||||
import { SharedService } from 'src/shared/services/shared.service';
|
||||
import * as crc from 'crc';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class PixSantanderService {
|
||||
|
||||
constructor(
|
||||
private http: HttpService,
|
||||
private orderService: OrderService) { }
|
||||
|
||||
async create(orderPayment: OrderPayment) {
|
||||
// const txid = '0';
|
||||
// this.http.put(`https://pix.santander.com.br/api/v1/sandbox/cob/${txid}`, null);
|
||||
//let authToken: SantanderPixAuthToken = null;
|
||||
const authToken = await this.getToken();
|
||||
const dateNow = new Date();
|
||||
const year = dateNow.getFullYear();
|
||||
const month = ("00" + (dateNow.getMonth() + 1)).slice(-2);
|
||||
const day = ("00" + dateNow.getDate()).slice(-2);
|
||||
|
||||
if (authToken.access_token !== null) {
|
||||
|
||||
const customer = await this.orderService.getCustomer(orderPayment.customerId);
|
||||
const calendario: Calendario = {
|
||||
dataDeVencimento: year + '-' + month + '-' + day,
|
||||
validadeAposVencimento: 1,
|
||||
};
|
||||
const devedor: Devedor = {
|
||||
logradouro: customer.enderent,
|
||||
cidade: customer.municent,
|
||||
uf: customer.estent,
|
||||
cep: customer.cepent,
|
||||
cpf: customer.cgcent,
|
||||
nome: customer.cliente
|
||||
}
|
||||
const valor: Valor = {
|
||||
original: orderPayment.amount,
|
||||
multa: null,
|
||||
desconto: null,
|
||||
juros: null,
|
||||
};
|
||||
|
||||
const pixCob: SantanderCreateCob = {
|
||||
calendario: calendario,
|
||||
devedor: devedor,
|
||||
valor: valor,
|
||||
chave: orderPayment.orderId.toString(),
|
||||
solicitacaoPagador: "Compra realizada na JURUNENSE"
|
||||
}
|
||||
|
||||
|
||||
console.log(pixCob);
|
||||
|
||||
return this.createCobPix(authToken, pixCob);
|
||||
}
|
||||
|
||||
return authToken;
|
||||
}
|
||||
|
||||
async createCobPix(token: SantanderPixAuthToken, data: SantanderCreateCob) {
|
||||
const config = {
|
||||
headers: {
|
||||
"Authorization": `Bearer ${token.access_token} `,
|
||||
"Content-Type": 'text/plain'
|
||||
},
|
||||
};
|
||||
|
||||
const request = this.http
|
||||
.post<SantanderCreatePix>("https://pix.santander.com.br/api/v1/sandbox/cob/987456123", data, config)
|
||||
.pipe(
|
||||
map((res) => {
|
||||
return res.data
|
||||
}),
|
||||
)
|
||||
.pipe(
|
||||
catchError((error) => {
|
||||
console.log(error);
|
||||
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
||||
}),
|
||||
);
|
||||
|
||||
const fact = await lastValueFrom(request);
|
||||
const storeName = "JURUNENSE HOME CENTER";
|
||||
const storeCity = "BELEM";
|
||||
const lengthTxId = fact.cobs[0].txid.length + 4;
|
||||
|
||||
let qrCodeDynamic = "000201" +
|
||||
"010212" +
|
||||
"26850014" +
|
||||
"br.gov.bcb.pix" +
|
||||
"2563" +
|
||||
fact.cobs[0].location +
|
||||
"52040000" +
|
||||
"5303986" +
|
||||
"54" +
|
||||
("00" + fact.cobs[0].valor.original.length).slice(-2) +
|
||||
fact.cobs[0].valor.original +
|
||||
"5402BR" +
|
||||
"59" + ("00" + storeName.length).slice(-2) +
|
||||
storeName + // deve ser o nome de fantasia da filial
|
||||
"60" + ("00" + storeCity.length).slice(-2) +
|
||||
storeCity + // deve ser a cidade da filial
|
||||
"62" + lengthTxId.toString() +
|
||||
fact.cobs[0].txid;//ver que informação é TXID
|
||||
|
||||
const crcValue = crc.crc16ccitt(qrCodeDynamic).toString(16);
|
||||
qrCodeDynamic += "6304" + crcValue
|
||||
|
||||
console.log(qrCodeDynamic);
|
||||
|
||||
return fact;
|
||||
}
|
||||
|
||||
|
||||
async getToken() {
|
||||
const data = QueryString.stringify({
|
||||
'client_id': 'yooItYcY7AYxWHwrjyBvIGcF9uEJDG1L',
|
||||
'client_secret': 'L0J47wlZ28ERlEfu'
|
||||
});
|
||||
const config = {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
};
|
||||
|
||||
const request = this.http
|
||||
.post<SantanderPixAuthToken>('https://pix.santander.com.br/sandbox/oauth/token?grant_type=client_credentials', data, config)
|
||||
.pipe(
|
||||
map((res) => {
|
||||
return res.data
|
||||
}),
|
||||
)
|
||||
.pipe(
|
||||
catchError((error) => {
|
||||
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
||||
}),
|
||||
);
|
||||
|
||||
const fact = await lastValueFrom(request);
|
||||
|
||||
return fact;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
https://docs.nestjs.com/providers#services
|
||||
*/
|
||||
|
||||
import { HttpService, Injectable, HttpException } from '@nestjs/common';
|
||||
import QueryString = require('qs');
|
||||
import { map, catchError, lastValueFrom } from 'rxjs';
|
||||
import { HttpStatus } from '@nestjs/common/enums';
|
||||
import { SantanderPixAuthToken } from './models/auth-token.model';
|
||||
import { Calendario, Devedor, SantanderCreateCob, Valor } from './models/create-cob.model';
|
||||
import { OrderService } from 'src/sales/order/order.service';
|
||||
import { OrderPayment } from './models/order-payment.model';
|
||||
import { SantanderCreatePix } from './models/cob-pix.model';
|
||||
import { SharedService } from 'src/shared/services/shared.service';
|
||||
import * as crc from 'crc';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class PixSantanderService {
|
||||
|
||||
constructor(
|
||||
private http: HttpService,
|
||||
private orderService: OrderService) { }
|
||||
|
||||
async create(orderPayment: OrderPayment) {
|
||||
// const txid = '0';
|
||||
// this.http.put(`https://pix.santander.com.br/api/v1/sandbox/cob/${txid}`, null);
|
||||
//let authToken: SantanderPixAuthToken = null;
|
||||
const authToken = await this.getToken();
|
||||
const dateNow = new Date();
|
||||
const year = dateNow.getFullYear();
|
||||
const month = ("00" + (dateNow.getMonth() + 1)).slice(-2);
|
||||
const day = ("00" + dateNow.getDate()).slice(-2);
|
||||
|
||||
if (authToken.access_token !== null) {
|
||||
|
||||
const customer = await this.orderService.getCustomer(orderPayment.customerId);
|
||||
const calendario: Calendario = {
|
||||
dataDeVencimento: year + '-' + month + '-' + day,
|
||||
validadeAposVencimento: 1,
|
||||
};
|
||||
const devedor: Devedor = {
|
||||
logradouro: customer.enderent,
|
||||
cidade: customer.municent,
|
||||
uf: customer.estent,
|
||||
cep: customer.cepent,
|
||||
cpf: customer.cgcent,
|
||||
nome: customer.cliente
|
||||
}
|
||||
const valor: Valor = {
|
||||
original: orderPayment.amount,
|
||||
multa: null,
|
||||
desconto: null,
|
||||
juros: null,
|
||||
};
|
||||
|
||||
const pixCob: SantanderCreateCob = {
|
||||
calendario: calendario,
|
||||
devedor: devedor,
|
||||
valor: valor,
|
||||
chave: orderPayment.orderId.toString(),
|
||||
solicitacaoPagador: "Compra realizada na JURUNENSE"
|
||||
}
|
||||
|
||||
|
||||
console.log(pixCob);
|
||||
|
||||
return this.createCobPix(authToken, pixCob);
|
||||
}
|
||||
|
||||
return authToken;
|
||||
}
|
||||
|
||||
async createCobPix(token: SantanderPixAuthToken, data: SantanderCreateCob) {
|
||||
const config = {
|
||||
headers: {
|
||||
"Authorization": `Bearer ${token.access_token} `,
|
||||
"Content-Type": 'text/plain'
|
||||
},
|
||||
};
|
||||
|
||||
const request = this.http
|
||||
.post<SantanderCreatePix>("https://pix.santander.com.br/api/v1/sandbox/cob/987456123", data, config)
|
||||
.pipe(
|
||||
map((res) => {
|
||||
return res.data
|
||||
}),
|
||||
)
|
||||
.pipe(
|
||||
catchError((error) => {
|
||||
console.log(error);
|
||||
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
||||
}),
|
||||
);
|
||||
|
||||
const fact = await lastValueFrom(request);
|
||||
const storeName = "JURUNENSE HOME CENTER";
|
||||
const storeCity = "BELEM";
|
||||
const lengthTxId = fact.cobs[0].txid.length + 4;
|
||||
|
||||
let qrCodeDynamic = "000201" +
|
||||
"010212" +
|
||||
"26850014" +
|
||||
"br.gov.bcb.pix" +
|
||||
"2563" +
|
||||
fact.cobs[0].location +
|
||||
"52040000" +
|
||||
"5303986" +
|
||||
"54" +
|
||||
("00" + fact.cobs[0].valor.original.length).slice(-2) +
|
||||
fact.cobs[0].valor.original +
|
||||
"5402BR" +
|
||||
"59" + ("00" + storeName.length).slice(-2) +
|
||||
storeName + // deve ser o nome de fantasia da filial
|
||||
"60" + ("00" + storeCity.length).slice(-2) +
|
||||
storeCity + // deve ser a cidade da filial
|
||||
"62" + lengthTxId.toString() +
|
||||
fact.cobs[0].txid;//ver que informação é TXID
|
||||
|
||||
const crcValue = crc.crc16ccitt(qrCodeDynamic).toString(16);
|
||||
qrCodeDynamic += "6304" + crcValue
|
||||
|
||||
console.log(qrCodeDynamic);
|
||||
|
||||
return fact;
|
||||
}
|
||||
|
||||
|
||||
async getToken() {
|
||||
const data = QueryString.stringify({
|
||||
'client_id': 'yooItYcY7AYxWHwrjyBvIGcF9uEJDG1L',
|
||||
'client_secret': 'L0J47wlZ28ERlEfu'
|
||||
});
|
||||
const config = {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
};
|
||||
|
||||
const request = this.http
|
||||
.post<SantanderPixAuthToken>('https://pix.santander.com.br/sandbox/oauth/token?grant_type=client_credentials', data, config)
|
||||
.pipe(
|
||||
map((res) => {
|
||||
return res.data
|
||||
}),
|
||||
)
|
||||
.pipe(
|
||||
catchError((error) => {
|
||||
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
||||
}),
|
||||
);
|
||||
|
||||
const fact = await lastValueFrom(request);
|
||||
|
||||
return fact;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,95 +1,95 @@
|
||||
/*
|
||||
https://docs.nestjs.com/controllers#controllers
|
||||
*/
|
||||
|
||||
import { Body, Controller, Get, HttpException, HttpStatus, Param, Post, Req } from '@nestjs/common';
|
||||
import { Cart } from 'src/domain/models/cart.model';
|
||||
import { ResultModel } from 'src/domain/models/result.model';
|
||||
import { PreOrderService } from './pre-order.service';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Pre-Order')
|
||||
@Controller('api/v1/preorder')
|
||||
export class PreOrderController {
|
||||
|
||||
constructor(private readonly preOrderService: PreOrderService) { }
|
||||
|
||||
@Post('create')
|
||||
async createOrder(@Body() cart: Cart) {
|
||||
try {
|
||||
const result = await this.preOrderService.create(cart);
|
||||
return new ResultModel(true, null, result, null);
|
||||
} catch (err) {
|
||||
throw new HttpException(new ResultModel(false, err.errors.message, {}, err),
|
||||
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get('list')
|
||||
async getPreOrders(@Req() request: any) {
|
||||
let sellerId = 0;
|
||||
let storeId = '';
|
||||
let start = new Date();
|
||||
let end = new Date();
|
||||
let idPreOrder = 0;
|
||||
let document = '';
|
||||
let nameCustomer = '';
|
||||
const query = request.query;
|
||||
if (query.store) {
|
||||
storeId = query.store;
|
||||
}
|
||||
if (query.start) {
|
||||
start = query.start;
|
||||
}
|
||||
if (query.end) {
|
||||
end = query.end;
|
||||
}
|
||||
if (query.seller) {
|
||||
sellerId = query.seller;
|
||||
}
|
||||
if (query.idPreOrder) {
|
||||
idPreOrder = query.idPreOrder;
|
||||
}
|
||||
if (query.document) {
|
||||
document = query.document;
|
||||
}
|
||||
if (query.nameCustomer) {
|
||||
nameCustomer = query.nameCustomer;
|
||||
}
|
||||
try {
|
||||
// if (sellerId == 0) {
|
||||
// throw new HttpException('Não foi informado um vendedor para a pesquisa de orçamentos.', HttpStatus.BAD_REQUEST);
|
||||
// }
|
||||
const result = await this.preOrderService.getPreOrders(sellerId, storeId, start, end, idPreOrder, document, nameCustomer);
|
||||
return new ResultModel(true, null, result, null);
|
||||
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@Get('cart')
|
||||
async getCartId(@Req() request: any) {
|
||||
console.log('consultando orçamento');
|
||||
let preOrderId = 0;
|
||||
const query = request.query;
|
||||
if (query.preOrderId) {
|
||||
preOrderId = query.preOrderId;
|
||||
}
|
||||
if (preOrderId == 0) {
|
||||
throw new HttpException('Informe um número de orçamento para realizar a pesquisa.', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return await this.preOrderService.getCartId(preOrderId);
|
||||
}
|
||||
|
||||
@Get('itens/:id')
|
||||
async getItensOrder(@Param('id') preOrderId: number) {
|
||||
console.log('consultando pedido de venda');
|
||||
if (preOrderId == 0) {
|
||||
throw new HttpException('Informe um número do orçamento de venda para realizar a pesquisa.', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return await this.preOrderService.getItensPreOrder(preOrderId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
https://docs.nestjs.com/controllers#controllers
|
||||
*/
|
||||
|
||||
import { Body, Controller, Get, HttpException, HttpStatus, Param, Post, Req } from '@nestjs/common';
|
||||
import { Cart } from 'src/domain/models/cart.model';
|
||||
import { ResultModel } from 'src/domain/models/result.model';
|
||||
import { PreOrderService } from './pre-order.service';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Pre-Order')
|
||||
@Controller('api/v1/preorder')
|
||||
export class PreOrderController {
|
||||
|
||||
constructor(private readonly preOrderService: PreOrderService) { }
|
||||
|
||||
@Post('create')
|
||||
async createOrder(@Body() cart: Cart) {
|
||||
try {
|
||||
const result = await this.preOrderService.create(cart);
|
||||
return new ResultModel(true, null, result, null);
|
||||
} catch (err) {
|
||||
throw new HttpException(new ResultModel(false, err.errors.message, {}, err),
|
||||
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get('list')
|
||||
async getPreOrders(@Req() request: any) {
|
||||
let sellerId = 0;
|
||||
let storeId = '';
|
||||
let start = new Date();
|
||||
let end = new Date();
|
||||
let idPreOrder = 0;
|
||||
let document = '';
|
||||
let nameCustomer = '';
|
||||
const query = request.query;
|
||||
if (query.store) {
|
||||
storeId = query.store;
|
||||
}
|
||||
if (query.start) {
|
||||
start = query.start;
|
||||
}
|
||||
if (query.end) {
|
||||
end = query.end;
|
||||
}
|
||||
if (query.seller) {
|
||||
sellerId = query.seller;
|
||||
}
|
||||
if (query.idPreOrder) {
|
||||
idPreOrder = query.idPreOrder;
|
||||
}
|
||||
if (query.document) {
|
||||
document = query.document;
|
||||
}
|
||||
if (query.nameCustomer) {
|
||||
nameCustomer = query.nameCustomer;
|
||||
}
|
||||
try {
|
||||
// if (sellerId == 0) {
|
||||
// throw new HttpException('Não foi informado um vendedor para a pesquisa de orçamentos.', HttpStatus.BAD_REQUEST);
|
||||
// }
|
||||
const result = await this.preOrderService.getPreOrders(sellerId, storeId, start, end, idPreOrder, document, nameCustomer);
|
||||
return new ResultModel(true, null, result, null);
|
||||
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@Get('cart')
|
||||
async getCartId(@Req() request: any) {
|
||||
console.log('consultando orçamento');
|
||||
let preOrderId = 0;
|
||||
const query = request.query;
|
||||
if (query.preOrderId) {
|
||||
preOrderId = query.preOrderId;
|
||||
}
|
||||
if (preOrderId == 0) {
|
||||
throw new HttpException('Informe um número de orçamento para realizar a pesquisa.', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return await this.preOrderService.getCartId(preOrderId);
|
||||
}
|
||||
|
||||
@Get('itens/:id')
|
||||
async getItensOrder(@Param('id') preOrderId: number) {
|
||||
console.log('consultando pedido de venda');
|
||||
if (preOrderId == 0) {
|
||||
throw new HttpException('Informe um número do orçamento de venda para realizar a pesquisa.', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return await this.preOrderService.getItensPreOrder(preOrderId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
import { PreOrderController } from './pre-order.controller';
|
||||
import { PreOrderService } from './pre-order.service';
|
||||
/*
|
||||
https://docs.nestjs.com/modules
|
||||
*/
|
||||
|
||||
import { Module } from '@nestjs/common';
|
||||
import { SharedModule } from 'src/shared/shared.module';
|
||||
import { ListsService } from 'src/backoffice/lists/lists.service';
|
||||
import { AddressCustomerService } from '../address-customer/address-customer.service';
|
||||
import { CustomerService } from '../customer/customer.service';
|
||||
|
||||
@Module({
|
||||
imports: [SharedModule],
|
||||
controllers: [
|
||||
PreOrderController,],
|
||||
providers: [
|
||||
PreOrderService,
|
||||
ListsService,
|
||||
CustomerService,
|
||||
AddressCustomerService],
|
||||
})
|
||||
export class PreOrderModule { }
|
||||
import { PreOrderController } from './pre-order.controller';
|
||||
import { PreOrderService } from './pre-order.service';
|
||||
/*
|
||||
https://docs.nestjs.com/modules
|
||||
*/
|
||||
|
||||
import { Module } from '@nestjs/common';
|
||||
import { SharedModule } from 'src/shared/shared.module';
|
||||
import { ListsService } from 'src/backoffice/lists/lists.service';
|
||||
import { AddressCustomerService } from '../address-customer/address-customer.service';
|
||||
import { CustomerService } from '../customer/customer.service';
|
||||
|
||||
@Module({
|
||||
imports: [SharedModule],
|
||||
controllers: [
|
||||
PreOrderController,],
|
||||
providers: [
|
||||
PreOrderService,
|
||||
ListsService,
|
||||
CustomerService,
|
||||
AddressCustomerService],
|
||||
})
|
||||
export class PreOrderModule { }
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
|
||||
import { Pcclient } from 'src/domain/entity/tables/pcclient.entity';
|
||||
import { SalesProduct } from 'src/domain/entity/views/esvprodutosvenda.entity';
|
||||
import { Connection, getConnection, QueryRunner } from 'typeorm';
|
||||
import { Connection, getConnection } from 'typeorm';
|
||||
import { Esvsituacaopedido } from '../../domain/entity/views/esvsituacaopedido.entity';
|
||||
import { Stock } from '../../domain/entity/views/esvestoquevenda.entity';
|
||||
import { FilterProduct } from 'src/domain/models/filter-product.model';
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
/*
|
||||
https://docs.nestjs.com/controllers#controllers
|
||||
*/
|
||||
|
||||
import { Body, Controller, Get, HttpException, HttpStatus, Post, Query } from '@nestjs/common';
|
||||
import { CalculatePriceTintometrico } from 'src/domain/models/calculate-price-tintometrico.model';
|
||||
import { TintometricoService } from './tintometrico.service';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Tintometrico')
|
||||
@Controller('api/v1/tintometrico')
|
||||
export class TintometricoController {
|
||||
|
||||
constructor(private readonly tintometricoService: TintometricoService){}
|
||||
|
||||
@Get('colors')
|
||||
async getColors(@Query() query) {
|
||||
let letter = '';
|
||||
let product = '';
|
||||
try {
|
||||
if (query['letter'])
|
||||
letter = query['letter'];
|
||||
if (query['product']) {
|
||||
product = query['product'];
|
||||
}
|
||||
return await this.tintometricoService.GetColors(letter, product);
|
||||
} catch (e) {
|
||||
throw new HttpException(e.message, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@Post('calculatePrice')
|
||||
async getPriceTintometrico(@Body() data: CalculatePriceTintometrico) {
|
||||
try{
|
||||
const dataPrice = await this.tintometricoService.calculatePriceColor(data);
|
||||
return dataPrice;
|
||||
} catch (e) {
|
||||
throw new HttpException(e.message, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
https://docs.nestjs.com/controllers#controllers
|
||||
*/
|
||||
|
||||
import { Body, Controller, Get, HttpException, HttpStatus, Post, Query } from '@nestjs/common';
|
||||
import { CalculatePriceTintometrico } from 'src/domain/models/calculate-price-tintometrico.model';
|
||||
import { TintometricoService } from './tintometrico.service';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Tintometrico')
|
||||
@Controller('api/v1/tintometrico')
|
||||
export class TintometricoController {
|
||||
|
||||
constructor(private readonly tintometricoService: TintometricoService){}
|
||||
|
||||
@Get('colors')
|
||||
async getColors(@Query() query) {
|
||||
let letter = '';
|
||||
let product = '';
|
||||
try {
|
||||
if (query['letter'])
|
||||
letter = query['letter'];
|
||||
if (query['product']) {
|
||||
product = query['product'];
|
||||
}
|
||||
return await this.tintometricoService.GetColors(letter, product);
|
||||
} catch (e) {
|
||||
throw new HttpException(e.message, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@Post('calculatePrice')
|
||||
async getPriceTintometrico(@Body() data: CalculatePriceTintometrico) {
|
||||
try{
|
||||
const dataPrice = await this.tintometricoService.calculatePriceColor(data);
|
||||
return dataPrice;
|
||||
} catch (e) {
|
||||
throw new HttpException(e.message, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { TintometricoController } from './tintometrico.controller';
|
||||
import { TintometricoService } from './tintometrico.service';
|
||||
/*
|
||||
https://docs.nestjs.com/modules
|
||||
*/
|
||||
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({
|
||||
imports: [TintometricoService],
|
||||
controllers: [
|
||||
TintometricoController,],
|
||||
providers: [
|
||||
TintometricoService,],
|
||||
})
|
||||
export class TintometricoModule { }
|
||||
import { TintometricoController } from './tintometrico.controller';
|
||||
import { TintometricoService } from './tintometrico.service';
|
||||
/*
|
||||
https://docs.nestjs.com/modules
|
||||
*/
|
||||
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({
|
||||
imports: [TintometricoService],
|
||||
controllers: [
|
||||
TintometricoController,],
|
||||
providers: [
|
||||
TintometricoService,],
|
||||
})
|
||||
export class TintometricoModule { }
|
||||
|
||||
@@ -1,58 +1,58 @@
|
||||
/*
|
||||
https://docs.nestjs.com/providers#services
|
||||
*/
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { connectionOptions } from 'src/configs/typeorm.config';
|
||||
import { CalculatePriceTintometrico } from 'src/domain/models/calculate-price-tintometrico.model';
|
||||
import { Connection } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class TintometricoService {
|
||||
|
||||
async GetColors(letter: string, product: string) {
|
||||
const connectionDb = new Connection(connectionOptions);
|
||||
await connectionDb.connect();
|
||||
const queryRunner = connectionDb.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = `SELECT DISTINCT PRODUCT as "line", NVL(COLORNAME, COLORID) as "colorName" ` +
|
||||
` FROM esttintometricoplanbase ` +
|
||||
` WHERE BASE = :1 AND PRODUCT = :2 ` +
|
||||
` ORDER BY NVL(COLORNAME, COLORID)`;
|
||||
const colors = await queryRunner.query(sql, [letter, product]);
|
||||
return colors;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connectionDb.close();
|
||||
}
|
||||
}
|
||||
|
||||
async calculatePriceColor(dataPrice: CalculatePriceTintometrico) {
|
||||
const connectionDb = new Connection(connectionOptions);
|
||||
await connectionDb.connect();
|
||||
const queryRunner = connectionDb.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = `SELECT ESK_VENDA.CALCULAR_PRECO_TINTOMETRICO(:1, :2, :3, :4, :5, :6) as "price_color" ` +
|
||||
` FROM DUAL`;
|
||||
const price = await queryRunner.query(sql, [dataPrice.storeId, dataPrice.productId,
|
||||
dataPrice.letter, dataPrice.line, dataPrice.color, dataPrice.can]);
|
||||
|
||||
const resultPrice = new CalculatePriceTintometrico(dataPrice.storeId, dataPrice.productId, dataPrice.letter,
|
||||
dataPrice.line, dataPrice.can, dataPrice.color, price[0].price_color );
|
||||
|
||||
return resultPrice;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connectionDb.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
https://docs.nestjs.com/providers#services
|
||||
*/
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { connectionOptions } from 'src/configs/typeorm.config';
|
||||
import { CalculatePriceTintometrico } from 'src/domain/models/calculate-price-tintometrico.model';
|
||||
import { Connection } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class TintometricoService {
|
||||
|
||||
async GetColors(letter: string, product: string) {
|
||||
const connectionDb = new Connection(connectionOptions);
|
||||
await connectionDb.connect();
|
||||
const queryRunner = connectionDb.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = `SELECT DISTINCT PRODUCT as "line", NVL(COLORNAME, COLORID) as "colorName" ` +
|
||||
` FROM esttintometricoplanbase ` +
|
||||
` WHERE BASE = :1 AND PRODUCT = :2 ` +
|
||||
` ORDER BY NVL(COLORNAME, COLORID)`;
|
||||
const colors = await queryRunner.query(sql, [letter, product]);
|
||||
return colors;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connectionDb.close();
|
||||
}
|
||||
}
|
||||
|
||||
async calculatePriceColor(dataPrice: CalculatePriceTintometrico) {
|
||||
const connectionDb = new Connection(connectionOptions);
|
||||
await connectionDb.connect();
|
||||
const queryRunner = connectionDb.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
try {
|
||||
const sql = `SELECT ESK_VENDA.CALCULAR_PRECO_TINTOMETRICO(:1, :2, :3, :4, :5, :6) as "price_color" ` +
|
||||
` FROM DUAL`;
|
||||
const price = await queryRunner.query(sql, [dataPrice.storeId, dataPrice.productId,
|
||||
dataPrice.letter, dataPrice.line, dataPrice.color, dataPrice.can]);
|
||||
|
||||
const resultPrice = new CalculatePriceTintometrico(dataPrice.storeId, dataPrice.productId, dataPrice.letter,
|
||||
dataPrice.line, dataPrice.can, dataPrice.color, price[0].price_color );
|
||||
|
||||
return resultPrice;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
await connectionDb.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user