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

GetProductReviews

Implements GetProductReviews Unified Method.

Source

import { defineApi } from "@vsf-enterprise/unified-api-bigcommerce";
import { ProductReview } from "@vsf-enterprise/bigcommerce-api";
import { getNormalizers } from "@vue-storefront/unified-data-model";

export const getProductReviews = defineApi.getProductReviews(async (context, args) => {
  const { normalizeProductReview, normalizePagination } = getNormalizers(context);

  const data = await context.api.getProductReviewCollection(
    {
      productId: Number.parseInt(args.productId),
    },
    {
      page: args.currentPage,
      limit: args.pageSize,
    },
  );

  return {
    reviews: data.data.map((element: ProductReview) => normalizeProductReview(element)),
    pagination: normalizePagination(data?.meta?.pagination ?? {}),
  };
});