From 8496b1c660dcbb1e902e5a00f5742ca9df05728b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matti=20R=C3=A4s=C3=A4nen?= Date: Wed, 14 Aug 2024 11:25:30 +0300 Subject: [PATCH] [Backend] Added undefined check for thesisStats to facultyThesisWriters --- .../src/services/faculty/facultyThesisWriters.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/services/backend/src/services/faculty/facultyThesisWriters.ts b/services/backend/src/services/faculty/facultyThesisWriters.ts index 705c4337fe..f2399f541d 100644 --- a/services/backend/src/services/faculty/facultyThesisWriters.ts +++ b/services/backend/src/services/faculty/facultyThesisWriters.ts @@ -73,11 +73,13 @@ const calculateCombinedStats = async ( const isMaster = degreeProgrammeType === degreeProgrammeTypes.master const correctIndex = isBachelor ? 0 : 1 - if (!combinedGraphStats[correctIndex].data) { - combinedGraphStats[correctIndex].data = [...thesisStats.data] - } else { - for (let i = 0; i < thesisStats.data.length; i++) { - combinedGraphStats[correctIndex].data[i] += thesisStats.data[i] + if (thesisStats) { + if (!combinedGraphStats[correctIndex].data) { + combinedGraphStats[correctIndex].data = [...thesisStats.data] + } else { + for (let i = 0; i < thesisStats.data.length; i++) { + combinedGraphStats[correctIndex].data[i] += thesisStats.data[i] + } } }