3
0
mirror of https://github.com/Qortal/q-shop.git synced 2025-01-30 14:52:20 +00:00

Filter reviews when calculating average rating

This commit is contained in:
QuickMythril 2024-04-12 14:56:35 -04:00
parent fea2a24217
commit 6922efd9ff

View File

@ -505,9 +505,12 @@ export const Store = () => {
// Modify resource into data that is more easily used on the front end
const storeRatingsArray = responseData.map((review: any) => {
const splitIdentifier = review.identifier.split("-");
// Return null if idenfier is not an exact match, because search is not case sensitive
const prefixIdentifier = splitIdentifier.slice(0, splitIdentifier.length - 2).join("-");
if (query !== prefixIdentifier) return null;
const rating = Number(splitIdentifier[splitIdentifier.length - 1]) / 10;
return rating;
});
}).filter((rating: number | null) => rating !== null); // Filter out null entries
// Calculate average rating of the store
let averageRating =