diff --git a/common.ts b/common.ts index 7987f96..bc845af 100644 --- a/common.ts +++ b/common.ts @@ -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, +} diff --git a/customer.ts b/customer.ts index 6d7fd9d..65e77e3 100644 --- a/customer.ts +++ b/customer.ts @@ -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 { 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()}`, { diff --git a/priceByCustomer.ts b/priceByCustomer.ts index 052fc8a..b31b0af 100644 --- a/priceByCustomer.ts +++ b/priceByCustomer.ts @@ -1,4 +1,6 @@ import { + QueryCustomer, + queryCustomerToSearchParams, HOST, Paginacion, paginacionToSearchParams, @@ -9,6 +11,7 @@ export interface PriceByCustomerQuery { paginacion?: Paginacion; /// Filtro por el código del cliente ("Code" en Customer.) filter?: string; + customer?: QueryCustomer; } export interface Precio { @@ -32,6 +35,9 @@ export async function getPricesByCustomer( if (options.filter) { searchParams.set("filter", options.filter); } + if (options.customer) { + queryCustomerToSearchParams(options.customer, searchParams); + } const res = await fetch( `${HOST}/api/Aperture/PriceByCustomer?${searchParams.toString()}`, {