From ee31c2fad4964b0fef070a643076595ff7a0522b Mon Sep 17 00:00:00 2001 From: aline-pereira Date: Tue, 7 Jan 2025 10:53:18 -0300 Subject: [PATCH] fix: removed converted function to reviews ordenation --- konfidency/actions/submitReviews.ts | 20 +++++++++-------- konfidency/loaders/productDetailsPage.ts | 24 ++++++++++---------- konfidency/manifest.gen.ts | 2 +- konfidency/utils/client.ts | 6 ++--- konfidency/utils/types.ts | 28 ++++++++++++------------ verified-reviews/utils/client.ts | 15 ++----------- 6 files changed, 44 insertions(+), 51 deletions(-) diff --git a/konfidency/actions/submitReviews.ts b/konfidency/actions/submitReviews.ts index d306ec18a..bd6562116 100644 --- a/konfidency/actions/submitReviews.ts +++ b/konfidency/actions/submitReviews.ts @@ -10,10 +10,13 @@ export interface Props { review: WriteReview; } -export default async function action(props: Props, _req: Request, ctx: AppContext): Promise { - - const { customer, api } = ctx - const { review, sku } = props +export default async function action( + props: Props, + _req: Request, + ctx: AppContext, +): Promise { + const { customer, api } = ctx; + const { review, sku } = props; try { const response = await api[`POST /:customer/:sku/review`]({ @@ -23,13 +26,12 @@ export default async function action(props: Props, _req: Request, ctx: AppContex body: { ...review, }, - }).then((r) => r.json()) - return await response + }).then((r) => r.json()); + return await response; } catch (error) { const errorObj = error as { name: string; message: string }; logger.error(`{ errorName: ${errorObj.name}, errorMessage: ${errorObj.message} }`); - return null + return null; } - -} \ No newline at end of file +} diff --git a/konfidency/loaders/productDetailsPage.ts b/konfidency/loaders/productDetailsPage.ts index 1766b889f..5e4d37989 100644 --- a/konfidency/loaders/productDetailsPage.ts +++ b/konfidency/loaders/productDetailsPage.ts @@ -5,9 +5,9 @@ import { toReview } from "../utils/transform.ts"; import { logger } from "@deco/deco/o11y"; export interface Props { /** - * @description Rating type, default: helpfulScore - * @default "helpfulScore" - */ + * @description Rating type, default: helpfulScore + * @default "helpfulScore" + */ sortField?: "helpfulScore" | "created" | "rating"; /** * @description Default value: asc @@ -24,7 +24,8 @@ export interface Props { page?: number; } export default function productDetailsPage( - { pageSize = 5, page = 1, sortField = "helpfulScore", sortOrder = "asc" }: Props, + { pageSize = 5, page = 1, sortField = "helpfulScore", sortOrder = "asc" }: + Props, _req: Request, ctx: AppContext, ): ExtensionOf { @@ -34,13 +35,14 @@ export default function productDetailsPage( return null; } try { - const reviews = await api["GET /:customer/:sku/summary/:sortField,:sortOrder"]({ - customer, - "sortField,:sortOrder": `${sortField},${sortOrder}`, - page, - pageSize, - sku: productDetailsPage.product.inProductGroupWithID as string, - }).then((res) => res.json()); + const reviews = await api + ["GET /:customer/:sku/summary/:sortField,:sortOrder"]({ + customer, + "sortField,:sortOrder": `${sortField},${sortOrder}`, + page, + pageSize, + sku: productDetailsPage.product.inProductGroupWithID as string, + }).then((res) => res.json()); const { aggregateRating, review } = toReview(reviews.reviews[0]); return { ...productDetailsPage, diff --git a/konfidency/manifest.gen.ts b/konfidency/manifest.gen.ts index 50cf505c0..0cc370e00 100644 --- a/konfidency/manifest.gen.ts +++ b/konfidency/manifest.gen.ts @@ -2,8 +2,8 @@ // This file SHOULD be checked into source version control. // This file is automatically updated during development when running `dev.ts`. -import * as $$$0 from "./loaders/productDetailsPage.ts"; import * as $$$$$$$$$0 from "./actions/submitReviews.ts"; +import * as $$$0 from "./loaders/productDetailsPage.ts"; const manifest = { "loaders": { diff --git a/konfidency/utils/client.ts b/konfidency/utils/client.ts index 973c1a1b3..94bf732c9 100644 --- a/konfidency/utils/client.ts +++ b/konfidency/utils/client.ts @@ -1,4 +1,4 @@ -import type { PDPReview, WriteReview, ResponseWriteReview } from "./types.ts"; +import type { PDPReview, ResponseWriteReview, WriteReview } from "./types.ts"; export interface API { "GET /:customer/:sku/summary/:sortField,:sortOrder": { @@ -10,7 +10,7 @@ export interface API { }; "POST /:customer/:sku/review": { - response: ResponseWriteReview + response: ResponseWriteReview; body: WriteReview; - } + }; } diff --git a/konfidency/utils/types.ts b/konfidency/utils/types.ts index 70b710d29..9dd3847fe 100644 --- a/konfidency/utils/types.ts +++ b/konfidency/utils/types.ts @@ -52,17 +52,17 @@ export interface WriteReview { } export interface ResponseWriteReview { - helpful: number; - unhelpful: number; - verified: boolean; - status: string; - _id: string; - created: string; - customer: string; - userId: string; - name: string; - sku: string; - text: string; - recommended: boolean; - rating: number; -} \ No newline at end of file + helpful: number; + unhelpful: number; + verified: boolean; + status: string; + _id: string; + created: string; + customer: string; + userId: string; + name: string; + sku: string; + text: string; + recommended: boolean; + rating: number; +} diff --git a/verified-reviews/utils/client.ts b/verified-reviews/utils/client.ts index 55293bd1c..7074d266e 100644 --- a/verified-reviews/utils/client.ts +++ b/verified-reviews/utils/client.ts @@ -20,15 +20,6 @@ export interface PaginationOptions { | "helpfulrating_DESC"; } -// creating an object to keep backward compatibility -const orderMap = { - date_desc: "date_desc", - date_ASC: "date_asc", - rate_DESC: "rate_desc", - rate_ASC: "rate_asc", - helpfulrating_DESC: "most_helpful", -} as const; - const MessageError = { ratings: "🔴⭐ Error on call ratings of Verified Review - probably unidentified product", @@ -96,14 +87,12 @@ export const createClient = (params: ConfigVerifiedReviews | undefined) => { }; /** @description https://documenter.getpostman.com/view/2336519/SVzw6MK5#daf51360-c79e-451a-b627-33bdd0ef66b8 */ const reviews = ( - { productId, count = 5, offset = 0, order: _order = "date_desc" }: + { productId, count, offset = 0, order = "date_desc" }: & PaginationOptions & { productId: string | string[]; }, ) => { - const order = orderMap[_order]; - const payload = { query: "reviews", product: Array.isArray(productId) ? productId : [productId], @@ -122,7 +111,7 @@ export const createClient = (params: ConfigVerifiedReviews | undefined) => { const fullReview = async ({ productId, - count = 5, + count, offset = 0, order, }: PaginationOptions & {