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 () => {
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) {