Compare commits

..

No commits in common. "issue-3" and "antifascista" have entirely different histories.

12 changed files with 80 additions and 82 deletions

View file

@ -78,7 +78,7 @@ export interface CustomerResponse {
export async function getCustomers( export async function getCustomers(
host: string, host: string,
headers: HeadersInit, token: string,
options: CustomerQuery options: CustomerQuery
): Promise<CustomerResponse> { ): Promise<CustomerResponse> {
let searchParams = new URLSearchParams(); let searchParams = new URLSearchParams();
@ -88,7 +88,11 @@ export async function getCustomers(
} }
const res = await fetch( const res = await fetch(
`${host}/api/Aperture/Customer?${searchParams.toString()}`, `${host}/api/Aperture/Customer?${searchParams.toString()}`,
{ headers } {
headers: {
accesstoken: token,
},
}
); );
const json = await res.json(); const json = await res.json();
console.debug(json); console.debug(json);

View file

@ -15,29 +15,17 @@ import {
getPriceLists, getPriceLists,
} from "../index.js"; } from "../index.js";
const hostInput = document.querySelector<HTMLInputElement>("#host")!; // TODO: hacerlo input
const userInput = document.querySelector<HTMLInputElement>("#user")!; const HOST = "http://sutty.vm:4001";
const passInput = document.querySelector<HTMLInputElement>("#pass")!;
const tokenInput = document.querySelector<HTMLInputElement>("#token-input")!; const tokenInput = document.querySelector<HTMLInputElement>("#token-input")!;
function headers() { if (localStorage.token) {
const h = new Headers(); tokenInput.value = localStorage.token;
h.set("content-type", "application/json");
if (tokenInput.value) {
h.set("accesstoken", tokenInput.value);
} else {
const basic = btoa(`${userInput.value}:${passInput.value}`);
h.set("authorization", `Basic ${basic}`);
}
return h;
} }
function host() { function token() {
return hostInput.value; return tokenInput.value;
} }
function clear(el: Node) { function clear(el: Node) {
@ -100,34 +88,34 @@ function setupForm(selector: string, listener: (event: Event) => Promise<any>) {
}); });
} }
setupForm("#token", () => { setupForm("#token", () => dummy(HOST, token()));
console.log(headers()); setupForm("#save-token", async () => {
return dummy(host(), headers()); localStorage.token = token();
}); });
setupForm("#productos", () => getProductos(host(), headers(), {})); setupForm("#productos", () => getProductos(HOST, token(), {}));
setupForm("#publicaciones", () => getPublications(host(), headers(), {})); setupForm("#publicaciones", () => getPublications(HOST, token(), {}));
setupForm("#price", (event) => setupForm("#price", (event) =>
getPrices(host(), headers(), { getPrices(HOST, token(), {
filter: (event.target! as any).filter.value, filter: (event.target! as any).filter.value,
}) })
); );
setupForm("#stock", (event) => setupForm("#stock", (event) =>
getStocks(host(), headers(), { getStocks(HOST, token(), {
filter: (event.target! as any).filter.value, filter: (event.target! as any).filter.value,
warehouseCode: (event.target! as any).warehouseCode.value, warehouseCode: (event.target! as any).warehouseCode.value,
}) })
); );
setupForm("#price-by-customer", (event) => setupForm("#price-by-customer", (event) =>
getPricesByCustomer(host(), headers(), { getPricesByCustomer(HOST, token(), {
filter: (event.target! as any).filter.value, filter: (event.target! as any).filter.value,
}) })
); );
setupForm("#price-list", (event) => setupForm("#price-list", (event) =>
getPriceLists(host(), headers(), { getPriceLists(HOST, token(), {
filter: (event.target! as any).filter.value, filter: (event.target! as any).filter.value,
}) })
); );
setupForm("#customers", () => getCustomers(host(), headers(), {})); setupForm("#customers", () => getCustomers(HOST, token(), {}));
let customer: Customer | null = null; let customer: Customer | null = null;
@ -135,7 +123,7 @@ setupForm("#pedido-customer", async (event) => {
const cuit = (event.target! as any).cuit.value; const cuit = (event.target! as any).cuit.value;
if (cuit.length === 0) throw new Error("No pusiste un CUIT."); if (cuit.length === 0) throw new Error("No pusiste un CUIT.");
const customers = await getCustomers(host(), headers(), { const customers = await getCustomers(HOST, token(), {
customer: { customer: {
type: TipoDeDocumento.CUIT, type: TipoDeDocumento.CUIT,
number: cuit, number: cuit,
@ -172,23 +160,17 @@ setupForm("#pedido-item", async (event) => {
const sku = (event.target! as any).sku.value; const sku = (event.target! as any).sku.value;
if (sku.length === 0) throw new Error("No pusiste un SKU."); if (sku.length === 0) throw new Error("No pusiste un SKU.");
const productosResponse = await getProductos(host(), headers(), { const productosResponse = await getProductos(HOST, token(), { filter: sku });
filter: sku,
});
if (productosResponse.Data.length !== 1) if (productosResponse.Data.length !== 1)
throw new Error("Encontré más de un producto."); throw new Error("Encontré más de un producto.");
const preciosDelClienteResponse = await getPricesByCustomer( const preciosDelClienteResponse = await getPricesByCustomer(HOST, token(), {
host(), SKUCode: sku,
headers(), customer: {
{ type: customer.DocumentType,
SKUCode: sku, number: customer.DocumentNumber,
customer: { },
type: customer.DocumentType, });
number: customer.DocumentNumber,
},
}
);
if (preciosDelClienteResponse.Data.length !== 1) if (preciosDelClienteResponse.Data.length !== 1)
throw new Error("Encontré más de un producto."); throw new Error("Encontré más de un producto.");
@ -234,5 +216,5 @@ setupForm("#pedido", async () => {
}, },
}; };
return await order(host(), headers(), orderJson); return await order(HOST, token(), orderJson);
}); });

View file

@ -31,15 +31,6 @@
} }
</style> </style>
<label for="host">Host: </label>
<input id="host" name="host" value="http://sutty.vm:4001" />
<label for="user">User: </label>
<input id="user" name="user" />
<label for="pass">Pass: </label>
<input id="pass" name="pass" value="" />
<label for="token-input">Access token: </label> <label for="token-input">Access token: </label>
<input id="token-input" name="token" /> <input id="token-input" name="token" />
@ -65,11 +56,7 @@
<form id="price"> <form id="price">
<button>Conseguir precios</button> <button>Conseguir precios</button>
<input <input name="filter" type="text" placeholder="Filtro por lista de precios (ID, opcional)" />
name="filter"
type="text"
placeholder="Filtro por lista de precios (ID, opcional)"
/>
<p class="status"></p> <p class="status"></p>
</form> </form>
@ -88,11 +75,7 @@
<form id="stock"> <form id="stock">
<button>Conseguir stock</button> <button>Conseguir stock</button>
<input name="filter" type="text" placeholder="Filtro por ID (opcional)" /> <input name="filter" type="text" placeholder="Filtro por ID (opcional)" />
<input <input name="warehouseCode" type="text" placeholder="Filtro por código de deposito (opcional)" />
name="warehouseCode"
type="text"
placeholder="Filtro por código de deposito (opcional)"
/>
<p class="status"></p> <p class="status"></p>
</form> </form>

View file

@ -1,7 +1,9 @@
export async function dummy(host: string, headers: HeadersInit) { export async function dummy(host: string, token: string) {
const res = await fetch(`${host}/api/Aperture/dummy`, { const res = await fetch(`${host}/api/Aperture/dummy`, {
method: "POST", method: "POST",
headers, headers: {
accesstoken: token,
},
}); });
const json = await res.json(); const json = await res.json();
if (!json.isOk) { if (!json.isOk) {

View file

@ -114,12 +114,15 @@ export interface OrderResponse {}
export async function order( export async function order(
host: string, host: string,
headers: HeadersInit, token: string,
order: OrderDto order: OrderDto
): Promise<OrderResponse> { ): Promise<OrderResponse> {
const res = await fetch(`${host}/api/Aperture/order`, { const res = await fetch(`${host}/api/Aperture/order`, {
method: "POST", method: "POST",
headers, headers: {
accesstoken: token,
"content-type": "application/json",
},
body: JSON.stringify(order), body: JSON.stringify(order),
}); });
const json = await res.json(); const json = await res.json();

View file

@ -1,6 +1,6 @@
{ {
"name": "@suttyweb/hyperpop", "name": "@suttyweb/hyperpop",
"version": "0.4.0", "version": "0.3.0",
"description": "Un cliente de API de https://github.com/TangoSoftware/ApiTiendas", "description": "Un cliente de API de https://github.com/TangoSoftware/ApiTiendas",
"license": "SEE LICENSE IN LICENSE", "license": "SEE LICENSE IN LICENSE",
"scripts": { "scripts": {

View file

@ -24,7 +24,7 @@ export interface PriceResponse {
export async function getPrices( export async function getPrices(
host: string, host: string,
headers: HeadersInit, token: string,
options: PriceQuery options: PriceQuery
): Promise<PriceResponse> { ): Promise<PriceResponse> {
let searchParams = new URLSearchParams(); let searchParams = new URLSearchParams();
@ -37,7 +37,11 @@ export async function getPrices(
} }
const res = await fetch( const res = await fetch(
`${host}/api/Aperture/Price?${searchParams.toString()}`, `${host}/api/Aperture/Price?${searchParams.toString()}`,
{ headers } {
headers: {
accesstoken: token,
},
}
); );
const json = await res.json(); const json = await res.json();
console.debug(json); console.debug(json);

View file

@ -28,7 +28,7 @@ export interface PreciosResponse {
export async function getPricesByCustomer( export async function getPricesByCustomer(
host: string, host: string,
headers: HeadersInit, token: string,
options: PriceByCustomerQuery options: PriceByCustomerQuery
): Promise<PreciosResponse> { ): Promise<PreciosResponse> {
let searchParams = new URLSearchParams(); let searchParams = new URLSearchParams();
@ -44,7 +44,11 @@ export async function getPricesByCustomer(
} }
const res = await fetch( const res = await fetch(
`${host}/api/Aperture/PriceByCustomer?${searchParams.toString()}`, `${host}/api/Aperture/PriceByCustomer?${searchParams.toString()}`,
{ headers } {
headers: {
accesstoken: token,
},
}
); );
const json = await res.json(); const json = await res.json();
console.debug(json); console.debug(json);

View file

@ -23,7 +23,7 @@ export interface PriceListResponse {
export async function getPriceLists( export async function getPriceLists(
host: string, host: string,
headers: HeadersInit, token: string,
options: PriceListQuery options: PriceListQuery
): Promise<PriceListResponse> { ): Promise<PriceListResponse> {
let searchParams = new URLSearchParams(); let searchParams = new URLSearchParams();
@ -33,7 +33,11 @@ export async function getPriceLists(
} }
const res = await fetch( const res = await fetch(
`${host}/api/Aperture/PriceList?${searchParams.toString()}`, `${host}/api/Aperture/PriceList?${searchParams.toString()}`,
{ headers } {
headers: {
accesstoken: token,
},
}
); );
const json = await res.json(); const json = await res.json();
console.debug(json); console.debug(json);

View file

@ -50,7 +50,7 @@ export interface ProductosResponse {
// https://github.com/TangoSoftware/ApiTiendas#art%C3%ADculos // https://github.com/TangoSoftware/ApiTiendas#art%C3%ADculos
export async function getProductos( export async function getProductos(
host: string, host: string,
headers: HeadersInit, token: string,
options: ProductosQuery options: ProductosQuery
): Promise<ProductosResponse> { ): Promise<ProductosResponse> {
let searchParams = new URLSearchParams(); let searchParams = new URLSearchParams();
@ -63,7 +63,11 @@ export async function getProductos(
} }
const res = await fetch( const res = await fetch(
`${host}/api/Aperture/Product?${searchParams.toString()}`, `${host}/api/Aperture/Product?${searchParams.toString()}`,
{ headers } {
headers: {
accesstoken: token,
},
}
); );
const json = await res.json(); const json = await res.json();
console.debug(json); console.debug(json);

View file

@ -23,7 +23,7 @@ export interface PublicationsResponse {
// https://github.com/TangoSoftware/ApiTiendas#art%C3%ADculos // https://github.com/TangoSoftware/ApiTiendas#art%C3%ADculos
export async function getPublications( export async function getPublications(
host: string, host: string,
headers: HeadersInit, token: string,
options: PublicationsQuery options: PublicationsQuery
): Promise<PublicationsResponse> { ): Promise<PublicationsResponse> {
let searchParams = new URLSearchParams(); let searchParams = new URLSearchParams();
@ -39,7 +39,11 @@ export async function getPublications(
} }
const res = await fetch( const res = await fetch(
`${host}/api/Aperture/Publications?${searchParams.toString()}`, `${host}/api/Aperture/Publications?${searchParams.toString()}`,
{ headers } {
headers: {
accesstoken: token,
},
}
); );
const json = await res.json(); const json = await res.json();
console.debug(json); console.debug(json);

View file

@ -23,7 +23,7 @@ export interface StockResponse {
// https://github.com/TangoSoftware/ApiTiendas#saldos-de-stock // https://github.com/TangoSoftware/ApiTiendas#saldos-de-stock
export async function getStocks( export async function getStocks(
host: string, host: string,
headers: HeadersInit, token: string,
options: StockQuery options: StockQuery
): Promise<StockResponse> { ): Promise<StockResponse> {
let searchParams = new URLSearchParams(); let searchParams = new URLSearchParams();
@ -36,7 +36,11 @@ export async function getStocks(
} }
const res = await fetch( const res = await fetch(
`${host}/api/Aperture/Stock?${searchParams.toString()}`, `${host}/api/Aperture/Stock?${searchParams.toString()}`,
{ headers } {
headers: {
accesstoken: token,
},
}
); );
const json = await res.json(); const json = await res.json();
console.debug(json); console.debug(json);