Softcodear HOST

This commit is contained in:
Cat /dev/Nulo 2021-11-15 18:57:36 -03:00
parent 689dc24850
commit be4fbc20e0
9 changed files with 33 additions and 49 deletions

View file

@ -1,6 +1,3 @@
// const HOST = 'https://tiendas.axoft.com'
export const HOST = "http://sutty.vm:4001";
export interface Paging {
/**
* Si hay más páginas disponibles

View file

@ -1,6 +1,5 @@
import {
QueryCustomer,
HOST,
Paginacion,
paginacionToSearchParams,
Paging,
@ -78,6 +77,7 @@ export interface CustomerResponse {
}
export async function getCustomers(
host: string,
token: string,
options: CustomerQuery
): Promise<CustomerResponse> {
@ -87,7 +87,7 @@ export async function getCustomers(
queryCustomerToSearchParams(options.customer, searchParams);
}
const res = await fetch(
`${HOST}/api/Aperture/Customer?${searchParams.toString()}`,
`${host}/api/Aperture/Customer?${searchParams.toString()}`,
{
headers: {
accesstoken: token,

View file

@ -14,6 +14,9 @@ import {
Publication,
} from "../index.js";
// TODO: hacerlo input
const HOST = "http://sutty.vm:4001";
const tokenInput = document.querySelector<HTMLInputElement>("#token-input")!;
if (localStorage.token) {
@ -80,17 +83,19 @@ function setupForm(selector: string, listener: (event: Event) => Promise<any>) {
});
}
setupForm("#token", () => dummy(token()));
setupForm("#token", () => dummy(HOST, token()));
setupForm("#save-token", async () => {
localStorage.token = token();
});
setupForm("#productos", () => getProductos(token(), {}));
setupForm("#publicaciones", () => getPublications(token(), {}));
setupForm("#price", () => getPrices(token(), {}));
setupForm("#productos", () => getProductos(HOST, token(), {}));
setupForm("#publicaciones", () => getPublications(HOST, token(), {}));
setupForm("#price", () => getPrices(HOST, token(), {}));
setupForm("#price-by-customer", (event) =>
getPricesByCustomer(token(), { filter: (event.target! as any).filter.value })
getPricesByCustomer(HOST, token(), {
filter: (event.target! as any).filter.value,
})
);
setupForm("#customers", () => getCustomers(token(), {}));
setupForm("#customers", () => getCustomers(HOST, token(), {}));
let customer: Customer | null = null;
@ -98,7 +103,7 @@ setupForm("#pedido-customer", async (event) => {
const cuit = (event.target! as any).cuit.value;
if (cuit.length === 0) throw new Error("No pusiste un CUIT.");
const customers = await getCustomers(token(), {
const customers = await getCustomers(HOST, token(), {
customer: {
type: TipoDeDocumento.CUIT,
number: cuit,
@ -135,11 +140,11 @@ setupForm("#pedido-item", async (event) => {
const sku = (event.target! as any).sku.value;
if (sku.length === 0) throw new Error("No pusiste un SKU.");
const productosResponse = await getProductos(token(), { filter: sku });
const productosResponse = await getProductos(HOST, token(), { filter: sku });
if (productosResponse.Data.length !== 1)
throw new Error("Encontré más de un producto.");
const preciosDelClienteResponse = await getPricesByCustomer(token(), {
const preciosDelClienteResponse = await getPricesByCustomer(HOST, token(), {
SKUCode: sku,
customer: {
type: customer.DocumentType,
@ -191,5 +196,5 @@ setupForm("#pedido", async (event) => {
},
};
return await order(token(), orderJson);
return await order(HOST, token(), orderJson);
});

View file

@ -1,7 +1,5 @@
import { HOST } from "./common.js";
export async function dummy(token: string) {
const res = await fetch(`${HOST}/api/Aperture/dummy`, {
export async function dummy(host: string, token: string) {
const res = await fetch(`${host}/api/Aperture/dummy`, {
method: "POST",
headers: {
accesstoken: token,

View file

@ -1,9 +1,4 @@
import {
HOST,
Paginacion,
paginacionToSearchParams,
Paging,
} from "./common.js";
import { Paginacion, paginacionToSearchParams, Paging } from "./common.js";
export interface OrderDto {
SituacionOrden?: null | string;
@ -118,10 +113,11 @@ export interface PaymentDto {
export interface OrderResponse {}
export async function order(
host: string,
token: string,
order: OrderDto
): Promise<OrderResponse> {
const res = await fetch(`${HOST}/api/Aperture/order`, {
const res = await fetch(`${host}/api/Aperture/order`, {
method: "POST",
headers: {
accesstoken: token,

View file

@ -1,9 +1,4 @@
import {
HOST,
Paginacion,
paginacionToSearchParams,
Paging,
} from "./common.js";
import { Paginacion, paginacionToSearchParams, Paging } from "./common.js";
export interface PriceQuery {
paginacion?: Paginacion;
@ -25,6 +20,7 @@ export interface PriceResponse {
}
export async function getPrices(
host: string,
token: string,
options: PriceQuery
): Promise<PriceResponse> {
@ -37,7 +33,7 @@ export async function getPrices(
searchParams.set("SKUCode", options.SKUCode);
}
const res = await fetch(
`${HOST}/api/Aperture/Price?${searchParams.toString()}`,
`${host}/api/Aperture/Price?${searchParams.toString()}`,
{
headers: {
accesstoken: token,

View file

@ -1,7 +1,6 @@
import {
QueryCustomer,
queryCustomerToSearchParams,
HOST,
Paginacion,
paginacionToSearchParams,
Paging,
@ -28,6 +27,7 @@ export interface PreciosResponse {
}
export async function getPricesByCustomer(
host: string,
token: string,
options: PriceByCustomerQuery
): Promise<PreciosResponse> {
@ -43,7 +43,7 @@ export async function getPricesByCustomer(
queryCustomerToSearchParams(options.customer, searchParams);
}
const res = await fetch(
`${HOST}/api/Aperture/PriceByCustomer?${searchParams.toString()}`,
`${host}/api/Aperture/PriceByCustomer?${searchParams.toString()}`,
{
headers: {
accesstoken: token,

View file

@ -1,9 +1,4 @@
import {
HOST,
Paginacion,
paginacionToSearchParams,
Paging,
} from "./common.js";
import { Paginacion, paginacionToSearchParams, Paging } from "./common.js";
export interface ProductosQuery {
paginacion?: Paginacion;
@ -54,6 +49,7 @@ export interface ProductosResponse {
// https://github.com/TangoSoftware/ApiTiendas#art%C3%ADculos
export async function getProductos(
host: string,
token: string,
options: ProductosQuery
): Promise<ProductosResponse> {
@ -66,7 +62,7 @@ export async function getProductos(
searchParams.set("filter", options.filter);
}
const res = await fetch(
`${HOST}/api/Aperture/Product?${searchParams.toString()}`,
`${host}/api/Aperture/Product?${searchParams.toString()}`,
{
headers: {
accesstoken: token,

View file

@ -1,9 +1,4 @@
import {
HOST,
Paginacion,
paginacionToSearchParams,
Paging,
} from "./common.js";
import { Paginacion, paginacionToSearchParams, Paging } from "./common.js";
export interface PublicationsQuery {
paginacion?: Paginacion;
@ -27,6 +22,7 @@ export interface PublicationsResponse {
// https://github.com/TangoSoftware/ApiTiendas#art%C3%ADculos
export async function getPublications(
host: string,
token: string,
options: PublicationsQuery
): Promise<PublicationsResponse> {
@ -42,7 +38,7 @@ export async function getPublications(
searchParams.set("variantCode", options.variantCode);
}
const res = await fetch(
`${HOST}/api/Aperture/Publications?${searchParams.toString()}`,
`${host}/api/Aperture/Publications?${searchParams.toString()}`,
{
headers: {
accesstoken: token,