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

GetOrders

Implements GetOrders Unified Method.

Source

import { defineApi, getCurrentCustomer, getOrderQuery } from "@vsf-enterprise/unified-api-commercetools";
import { getNormalizers } from "@vue-storefront/unified-data-model";
import { Order } from "@vsf-enterprise/commercetools-types";

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),
  };
});