From da0e31b97840fba379f7cfbe9fc09063afc3b16c Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 7 Jan 2025 11:17:56 +0100 Subject: [PATCH] fix: refs #7323 update getAbsences to handle multiple years for absence data --- src/pages/Worker/Card/WorkerTimeControl.vue | 27 +++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/pages/Worker/Card/WorkerTimeControl.vue b/src/pages/Worker/Card/WorkerTimeControl.vue index c480d5bd8..8d54cb810 100644 --- a/src/pages/Worker/Card/WorkerTimeControl.vue +++ b/src/pages/Worker/Card/WorkerTimeControl.vue @@ -208,13 +208,30 @@ const getWorkedHours = async (from, to) => { }; const getAbsences = async () => { - const params = { - workerFk: route.params.id, - businessFk: null, - year: startOfWeek.value.getFullYear(), + const startYear = startOfWeek.value.getFullYear(); + const endYear = endOfWeek.value.getFullYear(); + const defaultParams = { workerFk: route.params.id, businessFk: null }; + + const startData = ( + await axios.get('Calendars/absences', { + params: { ...defaultParams, year: startYear }, + }) + ).data; + + let endData; + if (startYear !== endYear) { + endData = ( + await axios.get('Calendars/absences', { + params: { ...defaultParams, year: endYear }, + }) + ).data; + } + + const data = { + holidays: [...(startData?.holidays || []), ...(endData?.holidays || [])], + absences: [...(startData?.absences || []), ...(endData?.absences || [])], }; - const { data } = await axios.get('Calendars/absences', { params }); if (data) addEvents(data); };