hyperpop.js/customer.ts

100 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

import {
QueryCustomer,
Paginacion,
paginacionToSearchParams,
Paging,
queryCustomerToSearchParams,
TipoDeDocumento,
} from "./common.js";
export interface CustomerQuery {
paginacion?: Paginacion;
customer?: QueryCustomer;
}
export interface Customer {
Code: string;
BusinessName: string;
TradeName: string;
Address: string;
PostalCode: string;
City: string;
ProvinceCode: string;
TradeAddress: string;
PhoneNumbers: string;
Email: string;
MobilePhoneNumber: string;
WebPage: string;
IvaCategoryCode: string;
DocumentType: TipoDeDocumento;
DocumentNumber: string;
PriceListNumber: number;
Discount: number;
Observations: string;
DisabledDate: string;
SellerCode: string;
CreditQuota: number;
LocalAccountBalance: number;
ForeignAccountBalance: number;
ForeignCurrencyClause: boolean;
CreditQuotaCurrencyCode: string;
UpdateDatetime?: null;
LastUpdateUtc?: string;
ShippingAddresses: ShippingAddress[];
CustomerComments: CustomerComment[];
SaleConditionCode: number;
TransportCode: string;
}
export interface CustomerComment {
Line: number;
Text: string;
}
export interface ShippingAddress {
Code: string;
Address: string;
ProvinceCode: string;
City: string;
PostalCode: string;
PhoneNumber1: string;
PhoneNumber2: string;
DefaultAddress: string;
Enabled: string;
DeliveryHours: string;
DeliversMonday: string;
DeliversTuesday: string;
DeliversWednesday: string;
DeliversThursday: string;
DeliversFriday: string;
DeliversSaturday: string;
DeliversSunday: string;
}
export interface CustomerResponse {
Paging: Paging;
Data: Customer[];
}
export async function getCustomers(
2021-11-15 21:57:36 +00:00
host: string,
2022-11-01 17:21:52 +00:00
headers: HeadersInit,
options: CustomerQuery
): Promise<CustomerResponse> {
let searchParams = new URLSearchParams();
paginacionToSearchParams(options.paginacion, searchParams);
if (options.customer) {
queryCustomerToSearchParams(options.customer, searchParams);
}
const res = await fetch(
2021-11-15 21:57:36 +00:00
`${host}/api/Aperture/Customer?${searchParams.toString()}`,
2022-11-01 17:21:52 +00:00
{ headers }
);
const json = await res.json();
console.debug(json);
if (json.Message) {
throw new Error(`Tango: ${json.Message}`);
}
return json;
}