problem with Reviews and Statics in Wix Store

this is the code of the Review Box lightbox

import wixWindow from 'wix-window';
import wixData from 'wix-data';

let productId;

$w.onReady(function () {
 
    productId = wixWindow.lightbox.getContext().productId;

 $w('#SubmitReviews').onBeforeSave(() => {
 if ($w('#radioRating').value === '') {
   $w('#rateError').show();
 return Promise.reject();
  }

  $w('#SubmitReviews').setFieldValues({
   productId,
   rating: $w('#radioRating').value,
   recommends: $w('#radioGroup1').value
  });
 });

 $w('#SubmitReviews').onAfterSave(async () => {
 await updateStatistics($w('#radioGroup1').value);
  wixWindow.lightbox.close();
 });
});

async function updateStatistics(isRecommended) {
 let stats = await wixData.get('review-stats', productId);

 if (stats) {
  stats.rating += parseInt($w('#radioRating').value, 10); 
  stats.count += 1; 
  stats.recommended += (isRecommended === "true") ? 1 : 0;
 return wixData.update('review-stats', stats)
 }
 
    stats = {
  _id: productId,
  rating: parseInt($w('#radioRating').value, 10),
  count: 1,
  recommended: (isRecommended === "true") ? 1 : 0
 };
 return wixData.insert('review-stats', stats)
}

export function radioRating_change(event, $w) {
 $w('#rateError').hide();
}