Skip to content

Commit

Permalink
Remove ratings that were found
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed Apr 15, 2023
1 parent ff95523 commit b4abf00
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions extensions/yourViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ const getFetcher = (
};

export default function AddYourViews(config: Props): ExtensionOf<Product> {
const client = getFetcher(config);
const aggregateRating = aggregateRatingFor(client);
const aggregateRating = aggregateRatingFor(getFetcher(config));

return {
aggregateRating,
Expand All @@ -58,9 +57,15 @@ const sameOrder = (
productIds: readonly string[],
elements: Rating[],
): (Rating | undefined)[] => {
const ordered = new Array<Rating | undefined>(productIds.length);
const ordered = new Array<Rating | undefined>(productIds.length).fill(
undefined,
);
for (let i = 0; i < productIds.length; i++) {
ordered[i] = elements.find((e) => e.ProductId === productIds[i]);
const ratingIdx = elements.findIndex((e) => e.ProductId === productIds[i]);
if (ratingIdx !== -1) {
ordered[i] = elements[ratingIdx];
elements.splice(ratingIdx, 1); // remove already found rating
}
}
return ordered;
};

0 comments on commit b4abf00

Please sign in to comment.