From e8b9003d03042aa351ff59560077c09948cb500d Mon Sep 17 00:00:00 2001 From: tara-97 <44540454+tara-97@users.noreply.github.com> Date: Tue, 29 Sep 2020 11:26:01 +0530 Subject: [PATCH] Fixed bug in doSetAverageRating function The doSetAverageRating is unable to update the rating when the last review is deleted as the reviews has length 0 for which it skips the if clause which update the rating. --- app_api/controllers/reviews.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app_api/controllers/reviews.js b/app_api/controllers/reviews.js index 76468a4..9c76237 100644 --- a/app_api/controllers/reviews.js +++ b/app_api/controllers/reviews.js @@ -75,6 +75,9 @@ var doSetAverageRating = function(location) { } ratingAverage = parseInt(ratingTotal / reviewCount, 10); location.rating = ratingAverage; + }else{ + location.rating = 0 + } location.save(function(err) { if (err) { console.log(err);