Compare commits

..

6 commits

9 changed files with 123 additions and 2 deletions

View file

@ -40,3 +40,26 @@ export function paginacionToSearchParams(
searchParams.set("pageNumber", "1");
}
}
export interface QueryCustomer {
type: TipoDeDocumento;
number: string;
}
export function queryCustomerToSearchParams(
cliente: QueryCustomer,
searchParams: URLSearchParams
) {
if (cliente) {
searchParams.set("documentType", cliente.type.toString());
searchParams.set("documentNumber", cliente.number);
}
}
export enum TipoDeDocumento {
CUIT = 80,
CUIL = 86,
CDI = 87,
LE = 89,
LC = 90,
DNI = 96,
}

View file

@ -1,12 +1,16 @@
import {
QueryCustomer,
HOST,
Paginacion,
paginacionToSearchParams,
Paging,
queryCustomerToSearchParams,
TipoDeDocumento,
} from "./common.js";
export interface CustomerQuery {
paginacion?: Paginacion;
customer?: QueryCustomer;
}
export interface Customer {
@ -23,7 +27,7 @@ export interface Customer {
MobilePhoneNumber: string;
WebPage: string;
IvaCategoryCode: string;
DocumentType: string;
DocumentType: TipoDeDocumento;
DocumentNumber: string;
PriceListNumber: number;
Discount: number;
@ -79,6 +83,9 @@ export async function getCustomers(
): Promise<CustomerResponse> {
let searchParams = new URLSearchParams();
paginacionToSearchParams(options.paginacion, searchParams);
if (options.customer) {
queryCustomerToSearchParams(options.customer, searchParams);
}
const res = await fetch(
`${HOST}/api/Aperture/Customer?${searchParams.toString()}`,
{

View file

@ -4,6 +4,7 @@ import {
getPrices,
getPricesByCustomer,
getCustomers,
getPublications,
} from "../index.js";
const tokenInput = document.querySelector<HTMLInputElement>("#token-input")!;
@ -77,6 +78,7 @@ setupForm("#save-token", async () => {
localStorage.token = token();
});
setupForm("#productos", () => getProductos(token(), {}));
setupForm("#publicaciones", () => getPublications(token(), {}));
setupForm("#price", () => getPrices(token(), {}));
setupForm("#price-by-customer", (event) =>
getPricesByCustomer(token(), { filter: (event.target! as any).filter.value })

View file

@ -38,6 +38,11 @@
<p class="status"></p>
</form>
<form id="publicaciones">
<button>Conseguir publicaciones</button>
<p class="status"></p>
</form>
<form id="price">
<button>Conseguir precios</button>
<p class="status"></p>

View file

@ -5,3 +5,4 @@ export * from "./product.js";
export * from "./price.js";
export * from "./priceByCustomer.js";
export * from "./customer.js";
export * from "./publications.js";

View file

@ -7,6 +7,8 @@ import {
export interface PriceQuery {
paginacion?: Paginacion;
filter?: string;
SKUCode?: string;
}
export interface Price {
@ -28,6 +30,12 @@ export async function getPrices(
): Promise<PriceResponse> {
let searchParams = new URLSearchParams();
paginacionToSearchParams(options.paginacion, searchParams);
if (options.filter) {
searchParams.set("filter", options.filter);
}
if (options.SKUCode) {
searchParams.set("SKUCode", options.SKUCode);
}
const res = await fetch(
`${HOST}/api/Aperture/Price?${searchParams.toString()}`,
{

View file

@ -1,4 +1,6 @@
import {
QueryCustomer,
queryCustomerToSearchParams,
HOST,
Paginacion,
paginacionToSearchParams,
@ -9,6 +11,8 @@ export interface PriceByCustomerQuery {
paginacion?: Paginacion;
/// Filtro por el código del cliente ("Code" en Customer.)
filter?: string;
SKUCode?: string;
customer?: QueryCustomer;
}
export interface Precio {
@ -32,6 +36,12 @@ export async function getPricesByCustomer(
if (options.filter) {
searchParams.set("filter", options.filter);
}
if (options.SKUCode) {
searchParams.set("SKUCode", options.SKUCode);
}
if (options.customer) {
queryCustomerToSearchParams(options.customer, searchParams);
}
const res = await fetch(
`${HOST}/api/Aperture/PriceByCustomer?${searchParams.toString()}`,
{

View file

@ -11,6 +11,7 @@ export interface ProductosQuery {
* Decide si solo traer los productos habilitados.
*/
onlyEnabled?: boolean;
filter?: string;
}
export interface Producto {
@ -61,6 +62,9 @@ export async function getProductos(
if ("onlyEnabled" in options) {
searchParams.set("onlyEnabled", options.onlyEnabled ? "true" : "false");
}
if (options.filter) {
searchParams.set("filter", options.filter);
}
const res = await fetch(
`${HOST}/api/Aperture/Product?${searchParams.toString()}`,
{
@ -69,7 +73,10 @@ export async function getProductos(
},
}
);
const json: ProductosResponse = await res.json();
const json = await res.json();
console.debug(json);
if (json.Message) {
throw new Error(`Tango: ${json.Message}`);
}
return json;
}

58
publications.ts Normal file
View file

@ -0,0 +1,58 @@
import {
HOST,
Paginacion,
paginacionToSearchParams,
Paging,
} from "./common.js";
export interface PublicationsQuery {
paginacion?: Paginacion;
productCode?: string;
skuCode?: string;
variantCode?: string;
}
export interface Publication {
ProductCode: string;
Description: string;
VariantCode?: string;
VariantDescription?: string;
SkuCode: string;
}
export interface PublicationsResponse {
Paging: Paging;
Data: Publication[];
}
// https://github.com/TangoSoftware/ApiTiendas#art%C3%ADculos
export async function getPublications(
token: string,
options: PublicationsQuery
): Promise<PublicationsResponse> {
let searchParams = new URLSearchParams();
paginacionToSearchParams(options.paginacion, searchParams);
if (options.skuCode) {
searchParams.set("skuCode", options.skuCode);
}
if (options.productCode) {
searchParams.set("productCode", options.productCode);
}
if (options.variantCode) {
searchParams.set("variantCode", options.variantCode);
}
const res = await fetch(
`${HOST}/api/Aperture/Publications?${searchParams.toString()}`,
{
headers: {
accesstoken: token,
},
}
);
const json = await res.json();
console.debug(json);
if (json.Message) {
throw new Error(`Tango: ${json.Message}`);
}
return json;
}