0
0
Fork 0

refactor: refs #7828 wip

This commit is contained in:
Jorge Penadés 2024-09-12 09:14:55 +02:00
parent d072a11c1b
commit 6b79d70551
1 changed files with 22 additions and 28 deletions

View File

@ -271,44 +271,38 @@ const fetchWorkerTimeControlMails = async (filter) => {
const fetchWeekData = async () => { const fetchWeekData = async () => {
try { try {
const filter = { const data = (
where: { await axios.get(`WorkerTimeControlMails/${route.params.id}/getWeeklyMail`, {
workerFk: route.params.id, params: {
year: selectedDate.value ? selectedDate.value?.getFullYear() : null, workerFk: route.params.id,
week: selectedWeekNumber.value, year: selectedDate.value.getFullYear(),
}, week: selectedWeekNumber.value,
}; },
})
const data = await fetchWorkerTimeControlMails(filter); ).data;
if (!data.length) { if (!data.length) state.value = null;
state.value = null; else {
} else {
const [mail] = data; const [mail] = data;
state.value = mail.state; state.value = mail.state;
reason.value = mail.reason; 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) { } catch (err) {
console.error('Error fetching week data'); 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) => { const setHours = (data) => {
for (const weekDay of weekDays.value) { for (const weekDay of weekDays.value) {
if (data) { if (data) {