Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: implementation of sortField and sortOrder fields #980

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading