Skip to content

Commit

Permalink
fix: implementation of sortField and sortOrder fields (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
ApMatheus authored Dec 19, 2024
1 parent a481a6b commit 54379b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions konfidency/loaders/productDetailsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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<ProductDetailsPage | null> {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion konfidency/utils/client.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 54379b3

Please sign in to comment.