From a00189d56ab49832f8f216539eba7be50fc3721c Mon Sep 17 00:00:00 2001 From: Dennis Boldt Date: Thu, 29 Apr 2021 21:30:23 +0200 Subject: [PATCH] Fix stats. --- api/src/routes/api/stats.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/src/routes/api/stats.js b/api/src/routes/api/stats.js index bf8380a..5f4805d 100644 --- a/api/src/routes/api/stats.js +++ b/api/src/routes/api/stats.js @@ -14,7 +14,7 @@ router.get( const publicTrackCount = await Track.find({ public: true }).count(); const userCount = await User.find().count(); - const aggregateResult = await Track.aggregate([ + const trackStats = await Track.aggregate([ { $addFields: { trackLength: '$statistics.length', @@ -39,7 +39,9 @@ router.get( }, ]); - const [trackLength, numEvents, trackDuration] = aggregateResult.length > 0 ? aggregateResult : [0,0,0]; + const [trackLength, numEvents, trackDuration] = trackStats.length > 0 + ? [trackStats[0].trackLength, trackStats[0].numEvents, trackStats[0].trackDuration] + : [0,0,0]; const trackLengthPrivatized = Math.floor(trackLength / TRACK_LENGTH_ROUNDING) * TRACK_LENGTH_ROUNDING;