From 54379b3aa82a9c845ec100e4438f20fa9926077f Mon Sep 17 00:00:00 2001 From: Matheus Aparecido <66977676+ApMatheus@users.noreply.github.com> Date: Thu, 19 Dec 2024 09:46:42 -0300 Subject: [PATCH] fix: implementation of sortField and sortOrder fields (#980) --- konfidency/loaders/productDetailsPage.ts | 15 +++++++++++++-- konfidency/utils/client.ts | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/konfidency/loaders/productDetailsPage.ts b/konfidency/loaders/productDetailsPage.ts index 7dce10635..1766b889f 100644 --- a/konfidency/loaders/productDetailsPage.ts +++ b/konfidency/loaders/productDetailsPage.ts @@ -4,6 +4,16 @@ import { AppContext } from "../mod.ts"; import { toReview } from "../utils/transform.ts"; import { logger } from "@deco/deco/o11y"; export interface Props { + /** + * @description Rating type, default: helpfulScore + * @default "helpfulScore" + */ + sortField?: "helpfulScore" | "created" | "rating"; + /** + * @description Default value: asc + * @default "asc" + */ + sortOrder?: "asc" | "desc"; /** * @description The default value is 5 */ @@ -14,7 +24,7 @@ export interface Props { page?: number; } export default function productDetailsPage( - { pageSize = 5, page = 1 }: Props, + { pageSize = 5, page = 1, sortField = "helpfulScore", sortOrder = "asc" }: Props, _req: Request, ctx: AppContext, ): ExtensionOf { @@ -24,8 +34,9 @@ export default function productDetailsPage( return null; } try { - const reviews = await api["GET /:customer/:sku/summary"]({ + const reviews = await api["GET /:customer/:sku/summary/:sortField,:sortOrder"]({ customer, + "sortField,:sortOrder": `${sortField},${sortOrder}`, page, pageSize, sku: productDetailsPage.product.inProductGroupWithID as string, diff --git a/konfidency/utils/client.ts b/konfidency/utils/client.ts index d818929fd..973c1a1b3 100644 --- a/konfidency/utils/client.ts +++ b/konfidency/utils/client.ts @@ -1,7 +1,7 @@ import type { PDPReview, WriteReview, ResponseWriteReview } from "./types.ts"; export interface API { - "GET /:customer/:sku/summary": { + "GET /:customer/:sku/summary/:sortField,:sortOrder": { response: PDPReview; searchParams: { page: number;