From 6b79d70551f4bdc981c20816d1b014f6d4162fa7 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 12 Sep 2024 09:14:55 +0200 Subject: [PATCH] refactor: refs #7828 wip --- src/pages/Worker/Card/WorkerTimeControl.vue | 50 +++++++++------------ 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/src/pages/Worker/Card/WorkerTimeControl.vue b/src/pages/Worker/Card/WorkerTimeControl.vue index abf60a078..2f66fbcc1 100644 --- a/src/pages/Worker/Card/WorkerTimeControl.vue +++ b/src/pages/Worker/Card/WorkerTimeControl.vue @@ -271,44 +271,38 @@ const fetchWorkerTimeControlMails = async (filter) => { const fetchWeekData = async () => { try { - const filter = { - where: { - workerFk: route.params.id, - year: selectedDate.value ? selectedDate.value?.getFullYear() : null, - week: selectedWeekNumber.value, - }, - }; - - const data = await fetchWorkerTimeControlMails(filter); - if (!data.length) { - state.value = null; - } else { + const data = ( + await axios.get(`WorkerTimeControlMails/${route.params.id}/getWeeklyMail`, { + params: { + workerFk: route.params.id, + year: selectedDate.value.getFullYear(), + week: selectedWeekNumber.value, + }, + }) + ).data; + if (!data.length) state.value = null; + else { const [mail] = data; state.value = mail.state; reason.value = mail.reason; } - await canBeResend(); + canResend.value = !!( + await axios.get('WorkerTimeControlMails/count', { + filter: { + where: { + year: selectedDate.value.getFullYear(), + week: selectedWeekNumber.value, + limit: 1, + }, + }, + }) + ).data.count; } catch (err) { console.error('Error fetching week data'); } }; -const canBeResend = async () => { - canResend.value = false; - - const filter = { - where: { - year: selectedDate.value.getFullYear(), - week: selectedWeekNumber.value, - }, - limit: 1, - }; - - const data = await fetchWorkerTimeControlMails(filter); - if (data.length) canResend.value = true; -}; - const setHours = (data) => { for (const weekDay of weekDays.value) { if (data) {