GetOrders
Implements GetOrders
Unified Method.
Source
import { assertAuthorized, defineApi, query } from "@vsf-enterprise/unified-api-magento";
import type { CustomerOrder } from "@vsf-enterprise/unified-api-magento/ecommerceTypes";
import { getNormalizers } from "@vsf-enterprise/unified-api-magento/udl";
export const getOrders = defineApi.getOrders(async (context, args) => {
await assertAuthorized(context);
const { normalizeOrderListItem, normalizePagination } = getNormalizers(context);
const { currentPage = 1, pageSize = 20 } = args ?? {};
const data = await query(
context.api.customerOrders({
pageSize,
currentPage,
}),
);
const { items, total_count, page_info } = data.customer?.orders ?? {};
return {
orders:
items?.filter(Boolean).map((order) => normalizeOrderListItem(order as CustomerOrder)) ?? [],
pagination: normalizePagination({ ...page_info, total_results: total_count! }),
};
});