-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to aggregate similar products to verified reviews (#634
) * feat: create verified reviews loader and fix types * fix: loader problem when product has no reviews * feat: add option to aggregate similar products reviews * revert order type * feat: add data to strucutred data
- Loading branch information
1 parent
74cbc95
commit bff2a88
Showing
7 changed files
with
153 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { AppContext } from "../mod.ts"; | ||
import { Review } from "../../commerce/types.ts"; | ||
import { createClient, PaginationOptions } from "../utils/client.ts"; | ||
import { toReview } from "../utils/transform.ts"; | ||
|
||
export type Props = PaginationOptions & { | ||
productId: string | string[]; | ||
}; | ||
|
||
/** | ||
* @title Opiniões verificadas - Full Review for Product (Ratings and Reviews) | ||
*/ | ||
export default async function productReviews( | ||
config: Props, | ||
_req: Request, | ||
ctx: AppContext, | ||
): Promise<Review[] | null> { | ||
const client = createClient({ ...ctx }); | ||
|
||
if (!client) { | ||
return null; | ||
} | ||
|
||
const reviewsResponse = await client.reviews({ | ||
productId: config.productId, | ||
count: config?.count, | ||
offset: config?.offset, | ||
order: config?.order, | ||
}); | ||
|
||
const reviews = reviewsResponse?.[0]; | ||
return reviews?.reviews?.map(toReview) ?? []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters