I have seen this article https://support.wix.com/en/article/corvid-tutorial-capturing-and-displaying-ratings . But it doesn’t really serves my requirement. What i have now is a lightbox that capture user’s rating input with their basic info, rating from 1 to 5, and rating description. Once submitted in the lightbox, it will do a write back to one of my dataset and then exit the lightbox.
Once user exit the lightbox and redirect to a page, i want to display the display rating that is the total and average of all reviews submitted by everyone. 3 parts to a typical display rating - on the left, it will capture the average rating in number, the middle part will be the number of stars as per the average, the right part will be the count of total ratings submitted.
The code i have now works for the right part to get the count. but the first two has ‘undefined’. I am very new to wix coding and hopefully get some help here.
import wixBookings from ‘wix-bookings’;
import wixData from ‘wix-data’;
wixData.query(“ReviewDataset”)
.count() //getting count of all reviews
.then( (num) => {
console.log(num);
$w(“#ratingsDisplay1”).numRatings = Number.parseInt(num) ; //putting count into display rating
} )
. catch ( (error) => {
let errorMsg = error.message;
let code = error.code;
} );
wixData.aggregate(" ReviewDataset “)
.avg(“customerRating”) //get average of all fields from ReviewDataset.customerRating
.run()
.then( (results) => {
$w(”#ratingsDisplay1").rating = Number.parseNum(results) ; //put average value to display rating
} )
. catch ( (error) => {
let errorMsg = error.message;
let code = error.code;
} );
I think the red font part above for the avg is not working. the rating part of the display rating requires a number field and i think the avg results is not in number. How can i cast it to number?