I can't figure out what i have wrong in my update statistics code

I’ve followed the guide here for adding review and ratings for products (im using for items) and the code is working for the reviews and they are automatically updated.
The guide i’ve followed is here: https://www.wix.com/code/home/example/Shop-Reviews
But the review statistics (average ratings is meant to be automatically updated too) isn’t working. I’ve changed the id where needed and changed the sumand numratings to align with my field keys. Not sure what’s going wrong. This is my code:

async function updateStatistics(isRecommended) {

let stats = await wixData.get(‘Review-stats’, projectName);

if (stats) {
stats.sum += parseInt($w(‘#radioRating’).value, 10);
stats.numRatings += 1;
return wixData.update(‘Review-stats’, stats)
}

stats = { 

_id: projectName,
sum: parseInt($w(‘#radioRating’).value, 10),
numRatings: 1,
};
return wixData.insert(‘Review-stats’, stats)
}

i’m bumping this… are there other tutorials or places i can find information? I want to understand why it isn’t working and would rather find out by myself if someone can point me to the right page to read/tutorial/video.

i have code on the same page for the reviews that are working fine but not the review stats. I’ve read through the code and it should work according to the explanation of the code. No data reaches the review-stats collection. Therefore I must be not linking review stats collection to my lightbox code.

For context, this is on a lightbox that acts as a user input review page, I have tried to change the ‘review-stats’ collection by adding the dataset to the lightbox page and directly linking the updatestatistics data to the dataset with the #reviewStats you can see.

This is the whole page code:

import wixWindow from ‘wix-window’;
import wixData from ‘wix-data’;

let projectName;

$w.onReady( function () {

projectName = wixWindow.lightbox.getContext() 

$w('#submitReviews').onBeforeSave(() => { 

if ($w(‘#radioButtons’).value === ‘null’) {
$w(‘#rateError’).show();
return Promise.reject();
}

    $w('#submitReviews').setFieldValues({ 
        projectName, 
        rating: $w('#radioButtons').value, 
    }); 
}); 

$w('#submitReviews').onAfterSave( **async**  () => { 
    wixWindow.lightbox.close(); 
}); 

});

async function updateStatistics(isRecommended) {
let stats = await wixData.get(‘#reviewStats’, projectName);

if (stats) {
stats.sum += parseInt($w(‘#radioButtons’).value, 10);
stats.numRatings += 1;
return wixData.update(‘#reviewStats’, stats)
}

stats = { 
    _id: projectName, 
    sum: parseInt($w('#radioButtons').value, 10), 
    numRatings: 1, 
}; 

return wixData.insert(‘#reviewStats’, stats)
}

I would suggest that you go back and read the tutorial again and check your code thoroughly as it looks like you are missing out parts here and there.

Also, make sure that you have one dataset on the lightbox page with all the code needed for the lightbox added, with the other dataset on the product page with all the code for that page added too.

Plus, if it tells you to do something or put somewhere, then do it as a simple action like not doing that could end up breaking the code.