Publications
This commit is contained in:
parent
b6d022add4
commit
452502835d
4 changed files with 66 additions and 0 deletions
|
@ -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";
|
||||||
|
|
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