From 6a550006d948b8d1b4c5fe79318bda8a64f8f183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Glasn=C3=A1k?= Date: Fri, 9 May 2025 13:36:51 +0200 Subject: [PATCH] fix(z-task-modal): fix edgecase for employees, where employee in the middle is not enterd --- .../plugins/tm@modal/task/z-task-modal.vue | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/app/src/plugins/tm@modal/task/z-task-modal.vue b/app/src/plugins/tm@modal/task/z-task-modal.vue index 7fdc2e6..4c27620 100644 --- a/app/src/plugins/tm@modal/task/z-task-modal.vue +++ b/app/src/plugins/tm@modal/task/z-task-modal.vue @@ -675,23 +675,31 @@ export default { this.$store.commit('tm/update_subtask', subtask); this.$events.emit('on-subtask-edited', this.subtask); } else { - this.subtask.employees.forEach((employee) => { - if (employee.id) - employee.timeblocks = this.timeblocks - .filter((timeblock) => timeblock.date) - .map((timeblock) => { - return { - start: `${moment(timeblock.date).format('YYYY-MM-DD')} ${ - timeblock.starts_at_time - }:00`, - end: `${moment(timeblock.date).format('YYYY-MM-DD')} ${ - timeblock.ends_at_time - }:00`, - id: null, - }; - }); + // Filter out employees that don't have both id and duration + const validEmployees = this.subtask.employees.filter( + (employee) => employee.id && employee.duration, + ); + + validEmployees.forEach((employee) => { + employee.timeblocks = this.timeblocks + .filter((timeblock) => timeblock.date) + .map((timeblock) => { + return { + start: `${moment(timeblock.date).format('YYYY-MM-DD')} ${ + timeblock.starts_at_time + }:00`, + end: `${moment(timeblock.date).format('YYYY-MM-DD')} ${ + timeblock.ends_at_time + }:00`, + id: null, + }; + }); }); - const subtaskCopy = this.subtask; + + const subtaskCopy = { + ...this.subtask, + employees: validEmployees, + }; delete subtaskCopy._master_task; const { subtasks } = await this.$axios.post_auth( `v1/mastertasks/${this.subtask.master_task_id}/subtasks`,