GetProductReviews
Implements GetProductReviews
Unified Method.
Source
import { defineApi } from "@vsf-enterprise/unified-api-bigcommerce";
import type { ProductReview } from "@vsf-enterprise/bigcommerce-api";
import { getNormalizers } from "@vsf-enterprise/unified-api-bigcommerce/udl";
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 ?? {}),
};
});