Compare commits
6 commits
c21e34cc07
...
3429b10896
Author | SHA1 | Date | |
---|---|---|---|
3429b10896 | |||
6070574ca9 | |||
452502835d | |||
b6d022add4 | |||
1a66628ec8 | |||
0e815bd07b |
9 changed files with 123 additions and 2 deletions
23
common.ts
23
common.ts
|
@ -40,3 +40,26 @@ export function paginacionToSearchParams(
|
||||||
searchParams.set("pageNumber", "1");
|
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,
|
||||||
|
}
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
import {
|
import {
|
||||||
|
QueryCustomer,
|
||||||
HOST,
|
HOST,
|
||||||
Paginacion,
|
Paginacion,
|
||||||
paginacionToSearchParams,
|
paginacionToSearchParams,
|
||||||
Paging,
|
Paging,
|
||||||
|
queryCustomerToSearchParams,
|
||||||
|
TipoDeDocumento,
|
||||||
} from "./common.js";
|
} from "./common.js";
|
||||||
|
|
||||||
export interface CustomerQuery {
|
export interface CustomerQuery {
|
||||||
paginacion?: Paginacion;
|
paginacion?: Paginacion;
|
||||||
|
customer?: QueryCustomer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Customer {
|
export interface Customer {
|
||||||
|
@ -23,7 +27,7 @@ export interface Customer {
|
||||||
MobilePhoneNumber: string;
|
MobilePhoneNumber: string;
|
||||||
WebPage: string;
|
WebPage: string;
|
||||||
IvaCategoryCode: string;
|
IvaCategoryCode: string;
|
||||||
DocumentType: string;
|
DocumentType: TipoDeDocumento;
|
||||||
DocumentNumber: string;
|
DocumentNumber: string;
|
||||||
PriceListNumber: number;
|
PriceListNumber: number;
|
||||||
Discount: number;
|
Discount: number;
|
||||||
|
@ -79,6 +83,9 @@ export async function getCustomers(
|
||||||
): Promise<CustomerResponse> {
|
): Promise<CustomerResponse> {
|
||||||
let searchParams = new URLSearchParams();
|
let searchParams = new URLSearchParams();
|
||||||
paginacionToSearchParams(options.paginacion, searchParams);
|
paginacionToSearchParams(options.paginacion, searchParams);
|
||||||
|
if (options.customer) {
|
||||||
|
queryCustomerToSearchParams(options.customer, searchParams);
|
||||||
|
}
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${HOST}/api/Aperture/Customer?${searchParams.toString()}`,
|
`${HOST}/api/Aperture/Customer?${searchParams.toString()}`,
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
getPrices,
|
getPrices,
|
||||||
getPricesByCustomer,
|
getPricesByCustomer,
|
||||||
getCustomers,
|
getCustomers,
|
||||||
|
getPublications,
|
||||||
} from "../index.js";
|
} from "../index.js";
|
||||||
|
|
||||||
const tokenInput = document.querySelector<HTMLInputElement>("#token-input")!;
|
const tokenInput = document.querySelector<HTMLInputElement>("#token-input")!;
|
||||||
|
@ -77,6 +78,7 @@ setupForm("#save-token", async () => {
|
||||||
localStorage.token = token();
|
localStorage.token = token();
|
||||||
});
|
});
|
||||||
setupForm("#productos", () => getProductos(token(), {}));
|
setupForm("#productos", () => getProductos(token(), {}));
|
||||||
|
setupForm("#publicaciones", () => getPublications(token(), {}));
|
||||||
setupForm("#price", () => getPrices(token(), {}));
|
setupForm("#price", () => getPrices(token(), {}));
|
||||||
setupForm("#price-by-customer", (event) =>
|
setupForm("#price-by-customer", (event) =>
|
||||||
getPricesByCustomer(token(), { filter: (event.target! as any).filter.value })
|
getPricesByCustomer(token(), { filter: (event.target! as any).filter.value })
|
||||||
|
|
|
@ -38,6 +38,11 @@
|
||||||
<p class="status"></p>
|
<p class="status"></p>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<form id="publicaciones">
|
||||||
|
<button>Conseguir publicaciones</button>
|
||||||
|
<p class="status"></p>
|
||||||
|
</form>
|
||||||
|
|
||||||
<form id="price">
|
<form id="price">
|
||||||
<button>Conseguir precios</button>
|
<button>Conseguir precios</button>
|
||||||
<p class="status"></p>
|
<p class="status"></p>
|
||||||
|
|
1
index.ts
1
index.ts
|
@ -5,3 +5,4 @@ export * from "./product.js";
|
||||||
export * from "./price.js";
|
export * from "./price.js";
|
||||||
export * from "./priceByCustomer.js";
|
export * from "./priceByCustomer.js";
|
||||||
export * from "./customer.js";
|
export * from "./customer.js";
|
||||||
|
export * from "./publications.js";
|
||||||
|
|
8
price.ts
8
price.ts
|
@ -7,6 +7,8 @@ import {
|
||||||
|
|
||||||
export interface PriceQuery {
|
export interface PriceQuery {
|
||||||
paginacion?: Paginacion;
|
paginacion?: Paginacion;
|
||||||
|
filter?: string;
|
||||||
|
SKUCode?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Price {
|
export interface Price {
|
||||||
|
@ -28,6 +30,12 @@ export async function getPrices(
|
||||||
): Promise<PriceResponse> {
|
): Promise<PriceResponse> {
|
||||||
let searchParams = new URLSearchParams();
|
let searchParams = new URLSearchParams();
|
||||||
paginacionToSearchParams(options.paginacion, searchParams);
|
paginacionToSearchParams(options.paginacion, searchParams);
|
||||||
|
if (options.filter) {
|
||||||
|
searchParams.set("filter", options.filter);
|
||||||
|
}
|
||||||
|
if (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()}`,
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import {
|
import {
|
||||||
|
QueryCustomer,
|
||||||
|
queryCustomerToSearchParams,
|
||||||
HOST,
|
HOST,
|
||||||
Paginacion,
|
Paginacion,
|
||||||
paginacionToSearchParams,
|
paginacionToSearchParams,
|
||||||
|
@ -9,6 +11,8 @@ export interface PriceByCustomerQuery {
|
||||||
paginacion?: Paginacion;
|
paginacion?: Paginacion;
|
||||||
/// Filtro por el código del cliente ("Code" en Customer.)
|
/// Filtro por el código del cliente ("Code" en Customer.)
|
||||||
filter?: string;
|
filter?: string;
|
||||||
|
SKUCode?: string;
|
||||||
|
customer?: QueryCustomer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Precio {
|
export interface Precio {
|
||||||
|
@ -32,6 +36,12 @@ export async function getPricesByCustomer(
|
||||||
if (options.filter) {
|
if (options.filter) {
|
||||||
searchParams.set("filter", 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(
|
const res = await fetch(
|
||||||
`${HOST}/api/Aperture/PriceByCustomer?${searchParams.toString()}`,
|
`${HOST}/api/Aperture/PriceByCustomer?${searchParams.toString()}`,
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,6 +11,7 @@ export interface ProductosQuery {
|
||||||
* Decide si solo traer los productos habilitados.
|
* Decide si solo traer los productos habilitados.
|
||||||
*/
|
*/
|
||||||
onlyEnabled?: boolean;
|
onlyEnabled?: boolean;
|
||||||
|
filter?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Producto {
|
export interface Producto {
|
||||||
|
@ -61,6 +62,9 @@ export async function getProductos(
|
||||||
if ("onlyEnabled" in options) {
|
if ("onlyEnabled" in options) {
|
||||||
searchParams.set("onlyEnabled", options.onlyEnabled ? "true" : "false");
|
searchParams.set("onlyEnabled", options.onlyEnabled ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
if (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()}`,
|
||||||
{
|
{
|
||||||
|
@ -69,7 +73,10 @@ export async function getProductos(
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const json: ProductosResponse = await res.json();
|
const json = await res.json();
|
||||||
console.debug(json);
|
console.debug(json);
|
||||||
|
if (json.Message) {
|
||||||
|
throw new Error(`Tango: ${json.Message}`);
|
||||||
|
}
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
58
publications.ts
Normal file
58
publications.ts
Normal 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;
|
||||||
|
}
|
Loading…
Reference in a new issue