From 6b79d70551f4bdc981c20816d1b014f6d4162fa7 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 12 Sep 2024 09:14:55 +0200 Subject: [PATCH 1/5] 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) { From 44fd356d63ee78589a3902ba1891ec41dd5d39ad Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 12 Sep 2024 13:19:31 +0200 Subject: [PATCH 2/5] feat: refs #7828 useAcl & cherry pick mail data worker --- src/pages/Worker/Card/WorkerTimeControl.vue | 63 +++++++-------------- 1 file changed, 22 insertions(+), 41 deletions(-) diff --git a/src/pages/Worker/Card/WorkerTimeControl.vue b/src/pages/Worker/Card/WorkerTimeControl.vue index 2f66fbcc1..3893305a5 100644 --- a/src/pages/Worker/Card/WorkerTimeControl.vue +++ b/src/pages/Worker/Card/WorkerTimeControl.vue @@ -12,7 +12,6 @@ import WorkerTimeControlCalendar from 'pages/Worker/Card/WorkerTimeControlCalend import useNotify from 'src/composables/useNotify.js'; import axios from 'axios'; -import { useRole } from 'src/composables/useRole'; import { useAcl } from 'src/composables/useAcl'; import { useWeekdayStore } from 'src/stores/useWeekdayStore'; import { useStateStore } from 'stores/useStateStore'; @@ -63,13 +62,16 @@ const selectedCalendarDates = ref([]); const selectedDateFormatted = ref(toDateString(defaultDate.value)); const arrayData = useArrayData('workerData'); - +const acl = useAcl(); const worker = computed(() => arrayData.store?.data); - -const isHr = computed(() => useRole().hasAny(['hr'])); - -const canSend = computed(() => useAcl().hasAny('WorkerTimeControl', 'sendMail', 'WRITE')); - +const canSend = computed(() => + acl.hasAny([{ model: 'WorkerTimeControl', props: 'sendMail', accessType: 'WRITE' }]) +); +const canUpdate = computed(() => + acl.hasAny([ + { model: 'WorkerTimeControl', props: 'updateMailState', accessType: 'WRITE' }, + ]) +); const isHimself = computed(() => user.value.id === Number(route.params.id)); const columns = computed(() => { @@ -257,46 +259,25 @@ const fetchHours = async () => { } }; -const fetchWorkerTimeControlMails = async (filter) => { - try { - const { data } = await axios.get('WorkerTimeControlMails', { - params: { filter: JSON.stringify(filter) }, - }); - - return data; - } catch (err) { - console.error('Error fetching worker time control mails'); - } -}; - const fetchWeekData = async () => { + const where = { + year: selectedDate.value.getFullYear(), + week: selectedWeekNumber.value, + }; try { - const data = ( - await axios.get(`WorkerTimeControlMails/${route.params.id}/getWeeklyMail`, { - params: { - workerFk: route.params.id, - year: selectedDate.value.getFullYear(), - week: selectedWeekNumber.value, - }, + const mail = ( + await axios.get(`Workers/${route.params.id}/mail`, { + params: { filter: { where } }, }) - ).data; - if (!data.length) state.value = null; + ).data[0]; + if (!mail) state.value = null; else { - const [mail] = data; state.value = mail.state; reason.value = mail.reason; } canResend.value = !!( - await axios.get('WorkerTimeControlMails/count', { - filter: { - where: { - year: selectedDate.value.getFullYear(), - week: selectedWeekNumber.value, - limit: 1, - }, - }, - }) + await axios.get('WorkerTimeControlMails/count', { params: { where } }) ).data.count; } catch (err) { console.error('Error fetching week data'); @@ -443,7 +424,7 @@ onMounted(async () => {
{ @click="isSatisfied()" /> { Date: Fri, 13 Sep 2024 10:13:03 +0200 Subject: [PATCH 3/5] chore: refs #7828 fix e2e --- test/cypress/integration/ticket/ticketDescriptor.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cypress/integration/ticket/ticketDescriptor.spec.js b/test/cypress/integration/ticket/ticketDescriptor.spec.js index 516b0f13d..8192b7c7c 100644 --- a/test/cypress/integration/ticket/ticketDescriptor.spec.js +++ b/test/cypress/integration/ticket/ticketDescriptor.spec.js @@ -5,7 +5,7 @@ describe('Ticket descriptor', () => { const warehouseValue = ':nth-child(1) > :nth-child(6) > .value > span'; const summaryHeader = '.summaryHeader > div'; const weight = 25; - const weightValue = ':nth-child(10) > .value > span'; + const weightValue = '.summaryBody.row :nth-child(1) > :nth-child(9) > .value > span'; beforeEach(() => { cy.login('developer'); cy.viewport(1920, 1080); From 48a5c15b9d8a466676c4b069a0e67b41f4b5c14c Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 13 Sep 2024 10:54:09 +0200 Subject: [PATCH 4/5] feat: refs #7828 create axios instance which no manage errors --- src/boot/axios.js | 8 ++++++-- src/pages/Worker/Card/WorkerTimeControl.vue | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/boot/axios.js b/src/boot/axios.js index 9b32275bd..99a163cca 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -5,8 +5,10 @@ import useNotify from 'src/composables/useNotify.js'; const session = useSession(); const { notify } = useNotify(); +const baseUrl = '/api/'; -axios.defaults.baseURL = '/api/'; +axios.defaults.baseURL = baseUrl; +const axiosNoError = axios.create({ baseURL: baseUrl }); const onRequest = (config) => { const token = session.getToken(); @@ -79,5 +81,7 @@ const onResponseError = (error) => { axios.interceptors.request.use(onRequest, onRequestError); axios.interceptors.response.use(onResponse, onResponseError); +axiosNoError.interceptors.request.use(onRequest); +axiosNoError.interceptors.response.use(onResponse); -export { onRequest, onResponseError }; +export { onRequest, onResponseError, axiosNoError }; diff --git a/src/pages/Worker/Card/WorkerTimeControl.vue b/src/pages/Worker/Card/WorkerTimeControl.vue index 3893305a5..9ae91f8ce 100644 --- a/src/pages/Worker/Card/WorkerTimeControl.vue +++ b/src/pages/Worker/Card/WorkerTimeControl.vue @@ -2,6 +2,7 @@ import { useI18n } from 'vue-i18n'; import { useRoute } from 'vue-router'; import { onMounted, ref, computed, onBeforeMount, nextTick, reactive } from 'vue'; +import { axiosNoError } from 'src/boot/axios'; import FetchData from 'components/FetchData.vue'; import WorkerTimeHourChip from 'pages/Worker/Card/WorkerTimeHourChip.vue'; @@ -266,10 +267,11 @@ const fetchWeekData = async () => { }; try { const mail = ( - await axios.get(`Workers/${route.params.id}/mail`, { + await axiosNoError.get(`Workers/${route.params.id}/mail`, { params: { filter: { where } }, }) ).data[0]; + if (!mail) state.value = null; else { state.value = mail.state; @@ -277,7 +279,7 @@ const fetchWeekData = async () => { } canResend.value = !!( - await axios.get('WorkerTimeControlMails/count', { params: { where } }) + await axiosNoError.get('WorkerTimeControlMails/count', { params: { where } }) ).data.count; } catch (err) { console.error('Error fetching week data'); From 0f604ea8b5eaf3485a4678326aa5e327f9154a81 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 13 Sep 2024 11:34:45 +0200 Subject: [PATCH 5/5] fix: refs #7500 fixed e2e test --- test/cypress/integration/entry/entryDms.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cypress/integration/entry/entryDms.spec.js b/test/cypress/integration/entry/entryDms.spec.js index ed4a3d79c..47dcdba9e 100644 --- a/test/cypress/integration/entry/entryDms.spec.js +++ b/test/cypress/integration/entry/entryDms.spec.js @@ -23,7 +23,7 @@ describe('EntryDms', () => { expect(value).to.have.length(newFileTd++); const newRowSelector = `tbody > :nth-child(${newFileTd})`; cy.waitForElement(newRowSelector); - cy.validateRow(newRowSelector, [u, u, u, u, 'ENTRADA ID 1']); + cy.validateRow(newRowSelector, [u, u, u, u, u, 'ENTRADA ID 1']); //Edit new dms const newDescription = 'entry id 1 modified'; @@ -38,7 +38,7 @@ describe('EntryDms', () => { cy.saveCard(); cy.reload(); - cy.validateRow(newRowSelector, [u, u, u, u, newDescription]); + cy.validateRow(newRowSelector, [u, u, u, u, u, newDescription]); }); }); });