From 21958cfdb43cbf941d8e2d723cfcf0ae8632467f Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 15 Jan 2025 16:10:33 +0100 Subject: [PATCH] fix: catch mail err --- src/pages/Worker/Card/WorkerTimeControl.vue | 27 +++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/pages/Worker/Card/WorkerTimeControl.vue b/src/pages/Worker/Card/WorkerTimeControl.vue index 65fbf4b43..919331e2d 100644 --- a/src/pages/Worker/Card/WorkerTimeControl.vue +++ b/src/pages/Worker/Card/WorkerTimeControl.vue @@ -283,21 +283,22 @@ const fetchWeekData = async () => { year: selectedDateYear.value, week: selectedWeekNumber.value, }; - const mail = ( - await axiosNoError.get(`Workers/${route.params.id}/mail`, { - params: { filter: { where } }, - }) - ).data[0]; + try { + const [{ data: mailData }, { data: countData }] = await Promise.all([ + axiosNoError.get(`Workers/${route.params.id}/mail`, { + params: { filter: { where } }, + }), + axiosNoError.get('WorkerTimeControlMails/count', { params: { where } }), + ]); - if (!mail) state.value = null; - else { - state.value = mail.state; - reason.value = mail.reason; + const mail = mailData[0]; + + state.value = mail?.state; + reason.value = mail?.reason; + canResend.value = !!countData.count; + } catch { + state.value = null; } - - canResend.value = !!( - await axiosNoError.get('WorkerTimeControlMails/count', { params: { where } }) - ).data.count; }; const setHours = (data) => {