Compare commits
1 commit
antifascis
...
orders
Author | SHA1 | Date | |
---|---|---|---|
fc20a8bec2 |
18 changed files with 87 additions and 213 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
||||||
dist/
|
build/
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
dist/
|
build/
|
||||||
|
|
15
common.ts
15
common.ts
|
@ -1,3 +1,6 @@
|
||||||
|
// const HOST = 'https://tiendas.axoft.com'
|
||||||
|
export const HOST = "http://sutty.vm:4001";
|
||||||
|
|
||||||
export interface Paging {
|
export interface Paging {
|
||||||
/**
|
/**
|
||||||
* Si hay más páginas disponibles
|
* Si hay más páginas disponibles
|
||||||
|
@ -53,10 +56,10 @@ export function queryCustomerToSearchParams(
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum TipoDeDocumento {
|
export enum TipoDeDocumento {
|
||||||
CUIT = "80",
|
CUIT = 80,
|
||||||
CUIL = "86",
|
CUIL = 86,
|
||||||
CDI = "87",
|
CDI = 87,
|
||||||
LE = "89",
|
LE = 89,
|
||||||
LC = "90",
|
LC = 90,
|
||||||
DNI = "96",
|
DNI = 96,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import {
|
import {
|
||||||
QueryCustomer,
|
QueryCustomer,
|
||||||
|
HOST,
|
||||||
Paginacion,
|
Paginacion,
|
||||||
paginacionToSearchParams,
|
paginacionToSearchParams,
|
||||||
Paging,
|
Paging,
|
||||||
|
@ -77,7 +78,6 @@ export interface CustomerResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCustomers(
|
export async function getCustomers(
|
||||||
host: string,
|
|
||||||
token: string,
|
token: string,
|
||||||
options: CustomerQuery
|
options: CustomerQuery
|
||||||
): Promise<CustomerResponse> {
|
): Promise<CustomerResponse> {
|
||||||
|
@ -87,7 +87,7 @@ export async function getCustomers(
|
||||||
queryCustomerToSearchParams(options.customer, searchParams);
|
queryCustomerToSearchParams(options.customer, searchParams);
|
||||||
}
|
}
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${host}/api/Aperture/Customer?${searchParams.toString()}`,
|
`${HOST}/api/Aperture/Customer?${searchParams.toString()}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
accesstoken: token,
|
accesstoken: token,
|
||||||
|
|
80
demo/demo.ts
80
demo/demo.ts
|
@ -3,7 +3,6 @@ import {
|
||||||
getProductos,
|
getProductos,
|
||||||
getPrices,
|
getPrices,
|
||||||
getPricesByCustomer,
|
getPricesByCustomer,
|
||||||
getStocks,
|
|
||||||
getCustomers,
|
getCustomers,
|
||||||
order,
|
order,
|
||||||
OrderDto,
|
OrderDto,
|
||||||
|
@ -12,12 +11,9 @@ import {
|
||||||
Producto,
|
Producto,
|
||||||
Precio,
|
Precio,
|
||||||
getPublications,
|
getPublications,
|
||||||
getPriceLists,
|
Publication,
|
||||||
} from "../index.js";
|
} from "../index.js";
|
||||||
|
|
||||||
// TODO: hacerlo input
|
|
||||||
const HOST = "http://sutty.vm:4001";
|
|
||||||
|
|
||||||
const tokenInput = document.querySelector<HTMLInputElement>("#token-input")!;
|
const tokenInput = document.querySelector<HTMLInputElement>("#token-input")!;
|
||||||
|
|
||||||
if (localStorage.token) {
|
if (localStorage.token) {
|
||||||
|
@ -55,22 +51,18 @@ function objectToDom(object: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function showResponse(statusEl: Element | null, promise: Promise<any>) {
|
async function showResponse(statusEl: Element | null, promise: Promise<any>) {
|
||||||
|
if (statusEl) clear(statusEl);
|
||||||
try {
|
try {
|
||||||
const response = await promise;
|
const response = await promise;
|
||||||
if (statusEl) {
|
if (statusEl) {
|
||||||
clear(statusEl);
|
|
||||||
statusEl.append("¡Funcionó!");
|
statusEl.append("¡Funcionó!");
|
||||||
if (response) {
|
if (response) {
|
||||||
statusEl.append(" Respuesta:", objectToDom(response));
|
statusEl.append(" Respuesta:", objectToDom(response));
|
||||||
}
|
}
|
||||||
} else alert(`¡Funcionó!${response ? ` Respuesta: ${response}` : ""}`);
|
} else alert(`¡Funcionó!${response ? ` Respuesta: ${response}` : ""}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (statusEl) {
|
if (statusEl) statusEl.append("Hubo un error :(", objectToDom(error));
|
||||||
clear(statusEl);
|
else alert(`Hubo un error: ${error}`);
|
||||||
statusEl.append("Hubo un error :(", objectToDom(error));
|
|
||||||
} else {
|
|
||||||
alert(`Hubo un error: ${error}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,34 +80,17 @@ function setupForm(selector: string, listener: (event: Event) => Promise<any>) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setupForm("#token", () => dummy(HOST, token()));
|
setupForm("#token", () => dummy(token()));
|
||||||
setupForm("#save-token", async () => {
|
setupForm("#save-token", async () => {
|
||||||
localStorage.token = token();
|
localStorage.token = token();
|
||||||
});
|
});
|
||||||
setupForm("#productos", () => getProductos(HOST, token(), {}));
|
setupForm("#productos", () => getProductos(token(), {}));
|
||||||
setupForm("#publicaciones", () => getPublications(HOST, token(), {}));
|
setupForm("#publicaciones", () => getPublications(token(), {}));
|
||||||
setupForm("#price", (event) =>
|
setupForm("#price", () => getPrices(token(), {}));
|
||||||
getPrices(HOST, token(), {
|
|
||||||
filter: (event.target! as any).filter.value,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
setupForm("#stock", (event) =>
|
|
||||||
getStocks(HOST, token(), {
|
|
||||||
filter: (event.target! as any).filter.value,
|
|
||||||
warehouseCode: (event.target! as any).warehouseCode.value,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
setupForm("#price-by-customer", (event) =>
|
setupForm("#price-by-customer", (event) =>
|
||||||
getPricesByCustomer(HOST, token(), {
|
getPricesByCustomer(token(), { filter: (event.target! as any).filter.value })
|
||||||
filter: (event.target! as any).filter.value,
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
setupForm("#price-list", (event) =>
|
setupForm("#customers", () => getCustomers(token(), {}));
|
||||||
getPriceLists(HOST, token(), {
|
|
||||||
filter: (event.target! as any).filter.value,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
setupForm("#customers", () => getCustomers(HOST, token(), {}));
|
|
||||||
|
|
||||||
let customer: Customer | null = null;
|
let customer: Customer | null = null;
|
||||||
|
|
||||||
|
@ -123,7 +98,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, token(), {
|
const customers = await getCustomers(token(), {
|
||||||
customer: {
|
customer: {
|
||||||
type: TipoDeDocumento.CUIT,
|
type: TipoDeDocumento.CUIT,
|
||||||
number: cuit,
|
number: cuit,
|
||||||
|
@ -142,14 +117,15 @@ const productosEl = document.querySelector<HTMLUListElement>(
|
||||||
let productos: {
|
let productos: {
|
||||||
producto: Producto;
|
producto: Producto;
|
||||||
precio: Precio;
|
precio: Precio;
|
||||||
|
publicacion: Publication;
|
||||||
}[] = [];
|
}[] = [];
|
||||||
function renderProductosEl() {
|
function renderProductosEl() {
|
||||||
clear(productosEl);
|
clear(productosEl);
|
||||||
|
|
||||||
for (const { producto, precio } of productos) {
|
for (const { producto, precio, publicacion } of productos) {
|
||||||
const itemEl = document.createElement("li");
|
const itemEl = document.createElement("li");
|
||||||
itemEl.append(
|
itemEl.append(
|
||||||
`${producto.Description} (precio de cliente: $${precio.Price}, SKUCode: ${producto.SKUCode})`
|
`${producto.Description} (precio de cliente: $${precio.Price}, ProductCode: ${publicacion.ProductCode})`
|
||||||
);
|
);
|
||||||
productosEl.append(itemEl);
|
productosEl.append(itemEl);
|
||||||
}
|
}
|
||||||
|
@ -160,11 +136,11 @@ 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, token(), { filter: sku });
|
const productosResponse = await getProductos(token(), { 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(HOST, token(), {
|
const preciosDelClienteResponse = await getPricesByCustomer(token(), {
|
||||||
SKUCode: sku,
|
SKUCode: sku,
|
||||||
customer: {
|
customer: {
|
||||||
type: customer.DocumentType,
|
type: customer.DocumentType,
|
||||||
|
@ -174,16 +150,24 @@ setupForm("#pedido-item", async (event) => {
|
||||||
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.");
|
||||||
|
|
||||||
|
// TODO: puede haber varias publicaciones que serían varias variantes... ¿creo?
|
||||||
|
const publicacionesResponse = await getPublications(token(), {
|
||||||
|
skuCode: sku,
|
||||||
|
});
|
||||||
|
if (publicacionesResponse.Data.length !== 1)
|
||||||
|
throw new Error("Encontré más de un producto.");
|
||||||
|
|
||||||
productos.push({
|
productos.push({
|
||||||
producto: productosResponse.Data[0],
|
producto: productosResponse.Data[0],
|
||||||
precio: preciosDelClienteResponse.Data[0],
|
precio: preciosDelClienteResponse.Data[0],
|
||||||
|
publicacion: publicacionesResponse.Data[0],
|
||||||
});
|
});
|
||||||
renderProductosEl();
|
renderProductosEl();
|
||||||
|
|
||||||
return productosResponse;
|
return productosResponse;
|
||||||
});
|
});
|
||||||
|
|
||||||
setupForm("#pedido", async () => {
|
setupForm("#pedido", async (event) => {
|
||||||
if (!customer) throw new Error("No seteaste lx cliente todavía.");
|
if (!customer) throw new Error("No seteaste lx cliente todavía.");
|
||||||
|
|
||||||
// Se supone que Total es:
|
// Se supone que Total es:
|
||||||
|
@ -199,22 +183,20 @@ setupForm("#pedido", async () => {
|
||||||
Total: total,
|
Total: total,
|
||||||
OrderID: id,
|
OrderID: id,
|
||||||
OrderNumber: id,
|
OrderNumber: id,
|
||||||
OrderItems: productos.map(({ producto, precio }) => ({
|
OrderItems: productos.map(({ producto, precio, publicacion }) => ({
|
||||||
Description: producto.Description,
|
Description: producto.Description,
|
||||||
UnitPrice: precio.Price,
|
UnitPrice: precio.Price,
|
||||||
Quantity: 1,
|
Quantity: 1,
|
||||||
ProductCode: producto.SKUCode,
|
ProductCode: publicacion.ProductCode,
|
||||||
})),
|
})),
|
||||||
Customer: {
|
Customer: {
|
||||||
CustomerID: 1,
|
CustomerID: 9999999999, // TODO: CustomerID
|
||||||
User: customer.BusinessName,
|
User: "Prueba", // TODO: User
|
||||||
IVACategoryCode: customer.IvaCategoryCode,
|
IVACategoryCode: customer.IvaCategoryCode,
|
||||||
Email: "api@axoft.com", // En prod: customer.Email, tenemos que usar esto porque el usuario de prueba no tiene Email
|
Email: customer.Email,
|
||||||
ProvinceCode: customer.ProvinceCode,
|
ProvinceCode: customer.ProvinceCode,
|
||||||
DocumentNumber: customer.DocumentNumber,
|
|
||||||
DocumentType: customer.DocumentType,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return await order(HOST, token(), orderJson);
|
return await order(token(), orderJson);
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,12 +23,6 @@
|
||||||
pre {
|
pre {
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
summary {
|
|
||||||
position: sticky;
|
|
||||||
top: 0px;
|
|
||||||
background: white;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<label for="token-input">Access token: </label>
|
<label for="token-input">Access token: </label>
|
||||||
|
@ -56,7 +50,6 @@
|
||||||
|
|
||||||
<form id="price">
|
<form id="price">
|
||||||
<button>Conseguir precios</button>
|
<button>Conseguir precios</button>
|
||||||
<input name="filter" type="text" placeholder="Filtro por lista de precios (ID, opcional)" />
|
|
||||||
<p class="status"></p>
|
<p class="status"></p>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
@ -66,22 +59,9 @@
|
||||||
<p class="status"></p>
|
<p class="status"></p>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<form id="price-list">
|
|
||||||
<button>Conseguir listas de precios</button>
|
|
||||||
<input name="filter" type="text" placeholder="Filtro por ID (opcional)" />
|
|
||||||
<p class="status"></p>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form id="stock">
|
|
||||||
<button>Conseguir stock</button>
|
|
||||||
<input name="filter" type="text" placeholder="Filtro por ID (opcional)" />
|
|
||||||
<input name="warehouseCode" type="text" placeholder="Filtro por código de deposito (opcional)" />
|
|
||||||
<p class="status"></p>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form id="customers">
|
<form id="customers">
|
||||||
<button>Conseguir clientes</button>
|
|
||||||
<p class="status"></p>
|
<p class="status"></p>
|
||||||
|
<button>Conseguir clientes</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
|
@ -102,4 +82,4 @@
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<script type="module" src="../dist/demo/demo.js"></script>
|
<script type="module" src="../build/demo/demo.js"></script>
|
||||||
|
|
6
dummy.ts
6
dummy.ts
|
@ -1,5 +1,7 @@
|
||||||
export async function dummy(host: string, token: string) {
|
import { HOST } from "./common.js";
|
||||||
const res = await fetch(`${host}/api/Aperture/dummy`, {
|
|
||||||
|
export async function dummy(token: string) {
|
||||||
|
const res = await fetch(`${HOST}/api/Aperture/dummy`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
accesstoken: token,
|
accesstoken: token,
|
||||||
|
|
2
index.ts
2
index.ts
|
@ -4,8 +4,6 @@ export * from "./dummy.js";
|
||||||
export * from "./product.js";
|
export * from "./product.js";
|
||||||
export * from "./price.js";
|
export * from "./price.js";
|
||||||
export * from "./priceByCustomer.js";
|
export * from "./priceByCustomer.js";
|
||||||
export * from "./priceList.js";
|
|
||||||
export * from "./stock.js";
|
|
||||||
export * from "./customer.js";
|
export * from "./customer.js";
|
||||||
export * from "./order.js";
|
export * from "./order.js";
|
||||||
export * from "./publications.js";
|
export * from "./publications.js";
|
||||||
|
|
15
order.ts
15
order.ts
|
@ -1,3 +1,10 @@
|
||||||
|
import {
|
||||||
|
HOST,
|
||||||
|
Paginacion,
|
||||||
|
paginacionToSearchParams,
|
||||||
|
Paging,
|
||||||
|
} from "./common.js";
|
||||||
|
|
||||||
export interface OrderDto {
|
export interface OrderDto {
|
||||||
SituacionOrden?: null | string;
|
SituacionOrden?: null | string;
|
||||||
Date: string;
|
Date: string;
|
||||||
|
@ -66,8 +73,6 @@ export interface OrderItemDto {
|
||||||
Quantity: number;
|
Quantity: number;
|
||||||
UnitPrice: number;
|
UnitPrice: number;
|
||||||
DiscountPercentage?: number;
|
DiscountPercentage?: number;
|
||||||
SelectMeasureUnit?: string;
|
|
||||||
MeasureCode?: string;
|
|
||||||
}
|
}
|
||||||
export interface ShippingDto {
|
export interface ShippingDto {
|
||||||
ShippingID: number;
|
ShippingID: number;
|
||||||
|
@ -113,21 +118,19 @@ export interface PaymentDto {
|
||||||
export interface OrderResponse {}
|
export interface OrderResponse {}
|
||||||
|
|
||||||
export async function order(
|
export async function order(
|
||||||
host: string,
|
|
||||||
token: string,
|
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,
|
accesstoken: token,
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(order),
|
|
||||||
});
|
});
|
||||||
const json = await res.json();
|
const json = await res.json();
|
||||||
console.debug(json);
|
console.debug(json);
|
||||||
if (!json.isOk) {
|
if (json.Message) {
|
||||||
throw new Error(`Tango: ${json.Message}`);
|
throw new Error(`Tango: ${json.Message}`);
|
||||||
}
|
}
|
||||||
return json;
|
return json;
|
||||||
|
|
10
package.json
10
package.json
|
@ -1,11 +1,10 @@
|
||||||
{
|
{
|
||||||
"name": "@suttyweb/hyperpop",
|
"name": "hyperpop",
|
||||||
"version": "0.3.0",
|
"version": "0.0.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",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"prepublish": "tsc",
|
|
||||||
"watch-build": "tsc --watch",
|
"watch-build": "tsc --watch",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"check-format": "prettier --check .",
|
"check-format": "prettier --check .",
|
||||||
|
@ -20,8 +19,7 @@
|
||||||
"api"
|
"api"
|
||||||
],
|
],
|
||||||
"author": "Sutty <hi@sutty.nl>",
|
"author": "Sutty <hi@sutty.nl>",
|
||||||
"main": "dist/index.js",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"types": "dist/index.d.ts",
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"prettier": "^2.4.1",
|
"prettier": "^2.4.1",
|
||||||
"typescript": "^4.4.3"
|
"typescript": "^4.4.3"
|
||||||
|
|
13
price.ts
13
price.ts
|
@ -1,10 +1,12 @@
|
||||||
import { Paginacion, paginacionToSearchParams, Paging } from "./common.js";
|
import {
|
||||||
|
HOST,
|
||||||
|
Paginacion,
|
||||||
|
paginacionToSearchParams,
|
||||||
|
Paging,
|
||||||
|
} from "./common.js";
|
||||||
|
|
||||||
export interface PriceQuery {
|
export interface PriceQuery {
|
||||||
paginacion?: Paginacion;
|
paginacion?: Paginacion;
|
||||||
/**
|
|
||||||
* Filtrar por PriceListNumber
|
|
||||||
*/
|
|
||||||
filter?: string;
|
filter?: string;
|
||||||
SKUCode?: string;
|
SKUCode?: string;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +25,6 @@ export interface PriceResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPrices(
|
export async function getPrices(
|
||||||
host: string,
|
|
||||||
token: string,
|
token: string,
|
||||||
options: PriceQuery
|
options: PriceQuery
|
||||||
): Promise<PriceResponse> {
|
): Promise<PriceResponse> {
|
||||||
|
@ -36,7 +37,7 @@ export async function getPrices(
|
||||||
searchParams.set("SKUCode", options.SKUCode);
|
searchParams.set("SKUCode", options.SKUCode);
|
||||||
}
|
}
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${host}/api/Aperture/Price?${searchParams.toString()}`,
|
`${HOST}/api/Aperture/Price?${searchParams.toString()}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
accesstoken: token,
|
accesstoken: token,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
QueryCustomer,
|
QueryCustomer,
|
||||||
queryCustomerToSearchParams,
|
queryCustomerToSearchParams,
|
||||||
|
HOST,
|
||||||
Paginacion,
|
Paginacion,
|
||||||
paginacionToSearchParams,
|
paginacionToSearchParams,
|
||||||
Paging,
|
Paging,
|
||||||
|
@ -27,7 +28,6 @@ export interface PreciosResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPricesByCustomer(
|
export async function getPricesByCustomer(
|
||||||
host: string,
|
|
||||||
token: string,
|
token: string,
|
||||||
options: PriceByCustomerQuery
|
options: PriceByCustomerQuery
|
||||||
): Promise<PreciosResponse> {
|
): Promise<PreciosResponse> {
|
||||||
|
@ -43,7 +43,7 @@ export async function getPricesByCustomer(
|
||||||
queryCustomerToSearchParams(options.customer, searchParams);
|
queryCustomerToSearchParams(options.customer, searchParams);
|
||||||
}
|
}
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${host}/api/Aperture/PriceByCustomer?${searchParams.toString()}`,
|
`${HOST}/api/Aperture/PriceByCustomer?${searchParams.toString()}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
accesstoken: token,
|
accesstoken: token,
|
||||||
|
|
48
priceList.ts
48
priceList.ts
|
@ -1,48 +0,0 @@
|
||||||
import { Paginacion, paginacionToSearchParams, Paging } from "./common.js";
|
|
||||||
|
|
||||||
export interface PriceListQuery {
|
|
||||||
paginacion?: Paginacion;
|
|
||||||
filter?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PriceList {
|
|
||||||
PriceListNumber: number;
|
|
||||||
Description: string;
|
|
||||||
CommonCurrency: boolean;
|
|
||||||
IvaIncluded: boolean;
|
|
||||||
InternalTaxIncluded: boolean;
|
|
||||||
ValidityDateSince: string;
|
|
||||||
ValidityDateUntil: string;
|
|
||||||
Disabled: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PriceListResponse {
|
|
||||||
Paging: Paging;
|
|
||||||
Data: PriceList[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getPriceLists(
|
|
||||||
host: string,
|
|
||||||
token: string,
|
|
||||||
options: PriceListQuery
|
|
||||||
): Promise<PriceListResponse> {
|
|
||||||
let searchParams = new URLSearchParams();
|
|
||||||
paginacionToSearchParams(options.paginacion, searchParams);
|
|
||||||
if (options.filter) {
|
|
||||||
searchParams.set("filter", options.filter);
|
|
||||||
}
|
|
||||||
const res = await fetch(
|
|
||||||
`${host}/api/Aperture/PriceList?${searchParams.toString()}`,
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
accesstoken: token,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const json = await res.json();
|
|
||||||
console.debug(json);
|
|
||||||
if (json.Message) {
|
|
||||||
throw new Error(`Tango: ${json.Message}`);
|
|
||||||
}
|
|
||||||
return json;
|
|
||||||
}
|
|
10
product.ts
10
product.ts
|
@ -1,4 +1,9 @@
|
||||||
import { Paginacion, paginacionToSearchParams, Paging } from "./common.js";
|
import {
|
||||||
|
HOST,
|
||||||
|
Paginacion,
|
||||||
|
paginacionToSearchParams,
|
||||||
|
Paging,
|
||||||
|
} from "./common.js";
|
||||||
|
|
||||||
export interface ProductosQuery {
|
export interface ProductosQuery {
|
||||||
paginacion?: Paginacion;
|
paginacion?: Paginacion;
|
||||||
|
@ -49,7 +54,6 @@ 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,
|
|
||||||
token: string,
|
token: string,
|
||||||
options: ProductosQuery
|
options: ProductosQuery
|
||||||
): Promise<ProductosResponse> {
|
): Promise<ProductosResponse> {
|
||||||
|
@ -62,7 +66,7 @@ export async function getProductos(
|
||||||
searchParams.set("filter", options.filter);
|
searchParams.set("filter", options.filter);
|
||||||
}
|
}
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${host}/api/Aperture/Product?${searchParams.toString()}`,
|
`${HOST}/api/Aperture/Product?${searchParams.toString()}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
accesstoken: token,
|
accesstoken: token,
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
import { Paginacion, paginacionToSearchParams, Paging } from "./common.js";
|
import {
|
||||||
|
HOST,
|
||||||
|
Paginacion,
|
||||||
|
paginacionToSearchParams,
|
||||||
|
Paging,
|
||||||
|
} from "./common.js";
|
||||||
|
|
||||||
export interface PublicationsQuery {
|
export interface PublicationsQuery {
|
||||||
paginacion?: Paginacion;
|
paginacion?: Paginacion;
|
||||||
|
@ -22,7 +27,6 @@ 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,
|
|
||||||
token: string,
|
token: string,
|
||||||
options: PublicationsQuery
|
options: PublicationsQuery
|
||||||
): Promise<PublicationsResponse> {
|
): Promise<PublicationsResponse> {
|
||||||
|
@ -38,7 +42,7 @@ export async function getPublications(
|
||||||
searchParams.set("variantCode", options.variantCode);
|
searchParams.set("variantCode", options.variantCode);
|
||||||
}
|
}
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${host}/api/Aperture/Publications?${searchParams.toString()}`,
|
`${HOST}/api/Aperture/Publications?${searchParams.toString()}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
accesstoken: token,
|
accesstoken: token,
|
||||||
|
|
51
stock.ts
51
stock.ts
|
@ -1,51 +0,0 @@
|
||||||
import { Paginacion, paginacionToSearchParams, Paging } from "./common.js";
|
|
||||||
|
|
||||||
export interface StockQuery {
|
|
||||||
paginacion?: Paginacion;
|
|
||||||
warehouseCode?: string;
|
|
||||||
filter?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Stock {
|
|
||||||
StoreNumber: number;
|
|
||||||
WarehouseCode: string;
|
|
||||||
SKUCode: string;
|
|
||||||
Quantity: number;
|
|
||||||
EngagedQuantity: number;
|
|
||||||
PendingQuantity: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StockResponse {
|
|
||||||
Paging: Paging;
|
|
||||||
Data: Stock[];
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/TangoSoftware/ApiTiendas#saldos-de-stock
|
|
||||||
export async function getStocks(
|
|
||||||
host: string,
|
|
||||||
token: string,
|
|
||||||
options: StockQuery
|
|
||||||
): Promise<StockResponse> {
|
|
||||||
let searchParams = new URLSearchParams();
|
|
||||||
paginacionToSearchParams(options.paginacion, searchParams);
|
|
||||||
if (options.filter) {
|
|
||||||
searchParams.set("filter", options.filter);
|
|
||||||
}
|
|
||||||
if (options.warehouseCode) {
|
|
||||||
searchParams.set("warehouseCode", options.warehouseCode);
|
|
||||||
}
|
|
||||||
const res = await fetch(
|
|
||||||
`${host}/api/Aperture/Stock?${searchParams.toString()}`,
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
accesstoken: token,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const json = await res.json();
|
|
||||||
console.debug(json);
|
|
||||||
if (json.Message) {
|
|
||||||
throw new Error(`Tango: ${json.Message}`);
|
|
||||||
}
|
|
||||||
return json;
|
|
||||||
}
|
|
|
@ -6,7 +6,7 @@
|
||||||
"module": "es6",
|
"module": "es6",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
|
|
||||||
"outDir": "./dist",
|
"outDir": "./build",
|
||||||
|
|
||||||
"allowJs": false,
|
"allowJs": false,
|
||||||
|
|
||||||
|
@ -15,8 +15,6 @@
|
||||||
|
|
||||||
"strict": true,
|
"strict": true,
|
||||||
|
|
||||||
"declaration": true,
|
|
||||||
|
|
||||||
"skipLibCheck": true
|
"skipLibCheck": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue