GetOrders
Implements GetOrders
Unified Method.
Source
import { defineApi, getCurrentCustomer } from "@vsf-enterprise/unified-api-commercetools";
import { getOrderQuery } from "@vsf-enterprise/unified-api-commercetools";
import type { Order } from "@vsf-enterprise/commercetools-types";
import { getNormalizers } from "@vsf-enterprise/unified-api-commercetools/udl";
export const getOrders = defineApi.getOrders(async (context, args) => {
await getCurrentCustomer(context);
const { normalizeOrderListItem, normalizePagination } = getNormalizers(context);
const { currentPage = 1, pageSize = 20 } = args ?? {};
const { orders, paginationData } = await getOrderQuery(context, { currentPage, pageSize });
return {
orders: orders.map((order: Order) => normalizeOrderListItem(order)),
pagination: normalizePagination(paginationData),
};
});