The Vue Storefront Essentials Course is now available! Learn More
GetOrders

GetOrders

Implements GetOrders Unified Method.

Source

import { getNormalizers } from "@vue-storefront/unified-data-model";
import { assertAuthorized, defineApi } from "@vsf-enterprise/unified-api-sapcc";

export const getOrders = defineApi.getOrders(async (context, args) => {
  assertAuthorized(context);
  const { currentPage = 1, pageSize = 20 } = args ?? {};

  const { orders, pagination } = await context.api.getUserOrderHistory({
    currentPage: currentPage - 1,
    pageSize,
  });
  const { normalizeOrderListItem, normalizePagination } = getNormalizers(context);

  const normalizedOrders = orders
    ? orders?.map((order) => normalizeOrderListItem(order)).filter(Boolean)
    : [];

  return {
    orders: normalizedOrders,
    pagination: normalizePagination(pagination),
  };
});