From 52981953f7e9efbc1a8875c321376e02a50c3b33 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 21 Oct 2024 13:23:45 +0200 Subject: [PATCH 01/17] feat(): refs #8039 canceledError not notify --- src/boot/axios.js | 5 +++-- src/boot/quasar.js | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/boot/axios.js b/src/boot/axios.js index 3bd80f487..d3e981adb 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -3,6 +3,7 @@ import { useSession } from 'src/composables/useSession'; import { Router } from 'src/router'; import useNotify from 'src/composables/useNotify.js'; import { useStateQueryStore } from 'src/stores/useStateQueryStore'; +import { CanceledError } from 'axios'; const session = useSession(); const { notify } = useNotify(); @@ -42,7 +43,7 @@ const onResponseError = (error) => { let message = ''; const response = error.response; - const responseData = response && response.data; + const responseData = response?.data; const responseError = responseData && response.data.error; if (responseError) { message = responseError.message; @@ -78,7 +79,7 @@ const onResponseError = (error) => { return Promise.reject(error); } - notify(message, 'negative'); + if (!(error instanceof CanceledError)) notify(message, 'negative'); return Promise.reject(error); }; diff --git a/src/boot/quasar.js b/src/boot/quasar.js index 5db6edd24..41a7990c7 100644 --- a/src/boot/quasar.js +++ b/src/boot/quasar.js @@ -3,6 +3,7 @@ import qFormMixin from './qformMixin'; import mainShortcutMixin from './mainShortcutMixin'; import keyShortcut from './keyShortcut'; import useNotify from 'src/composables/useNotify.js'; +import { CanceledError } from 'axios'; const { notify } = useNotify(); export default boot(({ app }) => { @@ -11,6 +12,6 @@ export default boot(({ app }) => { app.directive('shortcut', keyShortcut); app.config.errorHandler = function (err) { console.error(err); - notify('globals.error', 'negative', 'error'); + if (!(err instanceof CanceledError)) notify('globals.error', 'negative', 'error'); }; }); From 9780fe596fa0af4212f308a3150d1066a3275517 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 21 Oct 2024 13:33:12 +0200 Subject: [PATCH 02/17] feat: refs #8039 notify error unify --- src/boot/axios.js | 34 +--------------------------------- src/boot/quasar.js | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/boot/axios.js b/src/boot/axios.js index d3e981adb..b084b835d 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -40,37 +40,7 @@ const onResponse = (response) => { const onResponseError = (error) => { stateQuery.remove(error.config); - let message = ''; - - const response = error.response; - const responseData = response?.data; - const responseError = responseData && response.data.error; - if (responseError) { - message = responseError.message; - } - - switch (response?.status) { - case 422: - if (error.name == 'ValidationError') - message += - ' "' + - responseError.details.context + - '.' + - Object.keys(responseError.details.codes).join(',') + - '"'; - break; - case 500: - message = 'errors.statusInternalServerError'; - break; - case 502: - message = 'errors.statusBadGateway'; - break; - case 504: - message = 'errors.statusGatewayTimeout'; - break; - } - - if (session.isLoggedIn() && response?.status === 401) { + if (session.isLoggedIn() && error.response?.status === 401) { session.destroy(false); const hash = window.location.hash; const url = hash.slice(1); @@ -79,8 +49,6 @@ const onResponseError = (error) => { return Promise.reject(error); } - if (!(error instanceof CanceledError)) notify(message, 'negative'); - return Promise.reject(error); }; diff --git a/src/boot/quasar.js b/src/boot/quasar.js index 41a7990c7..bf5175ee6 100644 --- a/src/boot/quasar.js +++ b/src/boot/quasar.js @@ -10,8 +10,39 @@ export default boot(({ app }) => { app.mixin(qFormMixin); app.mixin(mainShortcutMixin); app.directive('shortcut', keyShortcut); - app.config.errorHandler = function (err) { - console.error(err); - if (!(err instanceof CanceledError)) notify('globals.error', 'negative', 'error'); + app.config.errorHandler = (error) => { + let message; + const response = error.response; + const responseData = response?.data; + const responseError = responseData && response.data.error; + if (responseError) { + message = responseError.message; + } + + switch (response?.status) { + case 422: + if (error.name == 'ValidationError') + message += + ' "' + + responseError.details.context + + '.' + + Object.keys(responseError.details.codes).join(',') + + '"'; + break; + case 500: + message = 'errors.statusInternalServerError'; + break; + case 502: + message = 'errors.statusBadGateway'; + break; + case 504: + message = 'errors.statusGatewayTimeout'; + break; + } + + console.error(error); + if (error instanceof CanceledError) return; + + notify(message ?? 'globals.error', 'negative', 'error'); }; }); From c69f7af3906e5d88f321350813ec42cc692bd6f4 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 21 Oct 2024 13:38:35 +0200 Subject: [PATCH 03/17] test: refs #8039 axios not notify --- test/vitest/__tests__/boot/axios.spec.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/test/vitest/__tests__/boot/axios.spec.js b/test/vitest/__tests__/boot/axios.spec.js index 7a802b4d2..19d396ec5 100644 --- a/test/vitest/__tests__/boot/axios.spec.js +++ b/test/vitest/__tests__/boot/axios.spec.js @@ -36,8 +36,6 @@ describe('Axios boot', () => { describe('onResponseError()', async () => { it('should call to the Notify plugin with a message error for an status code "500"', async () => { - Notify.create = vi.fn(); - const error = { response: { status: 500, @@ -45,19 +43,10 @@ describe('Axios boot', () => { }; const result = onResponseError(error); - expect(result).rejects.toEqual(expect.objectContaining(error)); - expect(Notify.create).toHaveBeenCalledWith( - expect.objectContaining({ - message: 'An internal server error has ocurred', - type: 'negative', - }) - ); }); it('should call to the Notify plugin with a message from the response property', async () => { - Notify.create = vi.fn(); - const error = { response: { status: 401, @@ -70,14 +59,7 @@ describe('Axios boot', () => { }; const result = onResponseError(error); - expect(result).rejects.toEqual(expect.objectContaining(error)); - expect(Notify.create).toHaveBeenCalledWith( - expect.objectContaining({ - message: 'Invalid user or password', - type: 'negative', - }) - ); }); }); }); From 9db1c4f721a3a0d5f3f3a103060a65b78bca4fa4 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 22 Oct 2024 12:29:33 +0200 Subject: [PATCH 04/17] fix: refs #8039 bad tests --- src/components/FormModel.vue | 3 --- test/cypress/integration/outLogin/logout.spec.js | 7 ++++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index 05f947cf3..9ac2d38a5 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -217,9 +217,6 @@ async function save() { updateAndEmit('onDataSaved', formData.value, response?.data); if ($props.reload) await arrayData.fetch({}); hasChanges.value = false; - } catch (err) { - console.error(err); - notify('errors.writeRequest', 'negative'); } finally { isLoading.value = false; } diff --git a/test/cypress/integration/outLogin/logout.spec.js b/test/cypress/integration/outLogin/logout.spec.js index 423189908..8d4e90aac 100644 --- a/test/cypress/integration/outLogin/logout.spec.js +++ b/test/cypress/integration/outLogin/logout.spec.js @@ -13,7 +13,7 @@ describe('Logout', () => { }); describe('not user', () => { beforeEach(() => { - cy.intercept('GET', '**/VnUsers/acl', { + cy.intercept('GET', '**DefaultViewConfigs**', { statusCode: 401, body: { error: { @@ -24,10 +24,11 @@ describe('Logout', () => { }, }, statusMessage: 'AUTHORIZATION_REQUIRED', - }).as('someRoute'); + }); }); + it('when token not exists', () => { - cy.reload(); + cy.get('.q-list > [href="#/item"]').click(); cy.get('.q-notification__message').should( 'have.text', 'Authorization Required' From a732ec05fbe6ba834d46c8eaf3d348c9dbcc0b01 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 22 Oct 2024 13:21:16 +0200 Subject: [PATCH 05/17] test: refs #8039 add hasNotify and, refactor: agencyWorkCenter test --- src/components/FormModelPopup.vue | 2 ++ .../route/agency/agencyWorkCenter.spec.js | 33 +++++++------------ test/cypress/support/commands.js | 11 +++++++ 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/components/FormModelPopup.vue b/src/components/FormModelPopup.vue index 118c8f5f4..d91f07535 100644 --- a/src/components/FormModelPopup.vue +++ b/src/components/FormModelPopup.vue @@ -61,6 +61,7 @@ defineExpose({ :loading="isLoading" @click="emit('onDataCanceled')" v-close-popup + data-cy="FormModelPopup_cancel" /> diff --git a/test/cypress/integration/route/agency/agencyWorkCenter.spec.js b/test/cypress/integration/route/agency/agencyWorkCenter.spec.js index 353c5805b..6a3cab664 100644 --- a/test/cypress/integration/route/agency/agencyWorkCenter.spec.js +++ b/test/cypress/integration/route/agency/agencyWorkCenter.spec.js @@ -7,31 +7,20 @@ describe('AgencyWorkCenter', () => { const createButton = '.q-page-sticky > div > .q-btn > .q-btn__content > .q-icon'; const workCenterCombobox = 'input[role="combobox"]'; - it('assign workCenter', () => { + it('check workCenter crud', () => { + // create cy.get(createButton).click(); cy.get(workCenterCombobox).type('workCenterOne{enter}'); - cy.get('.q-notification__message').should('have.text', 'Data created'); - }); + cy.hasNotify('Data created'); - it('delete workCenter', () => { + // expect error when duplicate + cy.get(createButton).click(); + cy.get('[data-cy="FormModelPopup_save"]').click(); + cy.hasNotify('This workCenter is already assigned to this agency'); + cy.get('[data-cy="FormModelPopup_cancel"]').click(); + + // delete cy.get('.q-item__section--side > .q-btn > .q-btn__content > .q-icon').click(); - cy.get('.q-notification__message').should( - 'have.text', - 'WorkCenter removed successfully' - ); - }); - - it('error on duplicate workCenter', () => { - cy.get(createButton).click(); - cy.get(workCenterCombobox).type('workCenterOne{enter}'); - cy.get('.q-notification__message').should('have.text', 'Data created'); - cy.get(createButton).click(); - cy.get( - '.vn-row > .q-field > .q-field__inner > .q-field__control > .q-field__control-container' - ).type('workCenterOne{enter}'); - - cy.get( - ':nth-child(2) > .q-notification__wrapper > .q-notification__content > .q-notification__message' - ).should('have.text', 'This workCenter is already assigned to this agency'); + cy.hasNotify('WorkCenter removed successfully'); }); }); diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index 83f45b721..c7b36cd3a 100755 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -254,3 +254,14 @@ Cypress.Commands.add('openUserPanel', () => { '.column > .q-avatar > .q-avatar__content > .q-img > .q-img__container > .q-img__image' ).click(); }); + +Cypress.Commands.add('hasNotify', (text) => { + //last + cy.get('.q-notification') + .should('be.visible') + .last() + .then(($lastNotification) => { + if (!Cypress.$($lastNotification).text().includes(text)) + throw new Error(`Notification not found: "${text}"`); + }); +}); From 2d81cffb3329bb874f32e41b3fe38c2eef6eb55e Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 22 Oct 2024 13:34:20 +0200 Subject: [PATCH 06/17] feat: refs #8039 show duplicate request in local --- src/boot/quasar.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/boot/quasar.js b/src/boot/quasar.js index bf5175ee6..7845719fe 100644 --- a/src/boot/quasar.js +++ b/src/boot/quasar.js @@ -4,6 +4,7 @@ import mainShortcutMixin from './mainShortcutMixin'; import keyShortcut from './keyShortcut'; import useNotify from 'src/composables/useNotify.js'; import { CanceledError } from 'axios'; + const { notify } = useNotify(); export default boot(({ app }) => { @@ -41,7 +42,11 @@ export default boot(({ app }) => { } console.error(error); - if (error instanceof CanceledError) return; + if (error instanceof CanceledError) { + const env = process.env.NODE_ENV; + if (env && env !== 'development') return; + message = 'Duplicate request'; + } notify(message ?? 'globals.error', 'negative', 'error'); }; From 0c9c01b6e9f2ea6fa3674301039eed2f6501e65d Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 22 Oct 2024 13:53:01 +0200 Subject: [PATCH 07/17] test: refs #8039 fix ZoneWarehouse e2e --- src/pages/Zone/Card/ZoneWarehouses.vue | 16 ++++------------ .../worker/workerNotificationsManager.spec.js | 5 +---- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/pages/Zone/Card/ZoneWarehouses.vue b/src/pages/Zone/Card/ZoneWarehouses.vue index 6b2933224..98e446797 100644 --- a/src/pages/Zone/Card/ZoneWarehouses.vue +++ b/src/pages/Zone/Card/ZoneWarehouses.vue @@ -34,21 +34,13 @@ const columns = computed(() => [ ]); const deleteWarehouse = async (row) => { - try { - await axios.delete(`${urlPath.value}/${row.id}`); - fetchWarehouses(); - } catch (error) { - console.error(error); - } + await axios.delete(`${urlPath.value}/${row.id}`); + fetchWarehouses(); }; const createZoneWarehouse = async (ZoneWarehouseFormData) => { - try { - await axios.post(urlPath.value, ZoneWarehouseFormData); - fetchWarehouses(); - } catch (error) { - console.error(error); - } + await axios.post(urlPath.value, ZoneWarehouseFormData); + fetchWarehouses(); }; watch( diff --git a/test/cypress/integration/worker/workerNotificationsManager.spec.js b/test/cypress/integration/worker/workerNotificationsManager.spec.js index ac452c4ff..367287a5a 100644 --- a/test/cypress/integration/worker/workerNotificationsManager.spec.js +++ b/test/cypress/integration/worker/workerNotificationsManager.spec.js @@ -17,10 +17,7 @@ describe('WorkerNotificationsManager', () => { cy.login('developer'); cy.visit(`/#/worker/${salesPersonId}/notifications`); cy.get(firstAvailableNotification).click(); - cy.notificationHas( - '.q-notification__message', - 'The notification subscription of this worker cant be modified' - ); + cy.hasNotify('The notification subscription of this worker cant be modified'); }); it('should active a notification that is yours', () => { From cd00a3c67f0fe72a4437f3a2eae3e7eae5266ebf Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 22 Oct 2024 13:55:35 +0200 Subject: [PATCH 08/17] test: refs #8039 fix WorkerNotification e2e --- src/pages/Worker/Card/WorkerNotificationsManager.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/Worker/Card/WorkerNotificationsManager.vue b/src/pages/Worker/Card/WorkerNotificationsManager.vue index 731e073cd..53571fb93 100644 --- a/src/pages/Worker/Card/WorkerNotificationsManager.vue +++ b/src/pages/Worker/Card/WorkerNotificationsManager.vue @@ -44,8 +44,9 @@ async function toggleNotification(notification) { `worker.notificationsManager.${notification.active ? '' : 'un'}subscribed` ), }); - } catch { + } catch (e) { notification.active = !notification.active; + throw e; } } From dd2dc86eea3d035aa6ee6845a1dd0047fb653db0 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 22 Oct 2024 14:05:15 +0200 Subject: [PATCH 09/17] fix: refs #8039 o not handle unnecessary errors --- src/pages/Account/Alias/Card/AliasUsers.vue | 10 +- src/pages/Account/Card/AccountMailAlias.vue | 20 +-- src/pages/Account/Role/Card/SubRoles.vue | 26 +-- .../Card/BasicData/TicketBasicDataForm.vue | 28 +-- .../Card/BasicData/TicketBasicDataView.vue | 85 ++++----- src/pages/Ticket/Card/ExpeditionNewTicket.vue | 32 ++-- src/pages/Ticket/Card/TicketComponents.vue | 26 +-- src/pages/Ticket/Card/TicketExpedition.vue | 58 +++---- .../Ticket/Card/TicketSaleMoreActions.vue | 12 +- src/pages/Ticket/Card/TicketSaleTracking.vue | 164 +++++++----------- src/pages/Ticket/Card/TicketService.vue | 52 +++--- src/pages/Ticket/Card/TicketVolume.vue | 22 +-- src/pages/Ticket/TicketAdvanceFilter.vue | 24 ++- src/pages/Ticket/TicketFutureFilter.vue | 40 ++--- 14 files changed, 228 insertions(+), 371 deletions(-) diff --git a/src/pages/Account/Alias/Card/AliasUsers.vue b/src/pages/Account/Alias/Card/AliasUsers.vue index 4a9c449e4..4aad68f1a 100644 --- a/src/pages/Account/Alias/Card/AliasUsers.vue +++ b/src/pages/Account/Alias/Card/AliasUsers.vue @@ -46,13 +46,9 @@ const columns = computed(() => [ ]); const deleteAlias = async (row) => { - try { - await axios.delete(`${urlPath.value}/${row.id}`); - notify(t('User removed'), 'positive'); - fetchAliases(); - } catch (error) { - console.error(error); - } + await axios.delete(`${urlPath.value}/${row.id}`); + notify(t('User removed'), 'positive'); + fetchAliases(); }; watch( diff --git a/src/pages/Account/Card/AccountMailAlias.vue b/src/pages/Account/Card/AccountMailAlias.vue index 15d03c665..8d3bd3b67 100644 --- a/src/pages/Account/Card/AccountMailAlias.vue +++ b/src/pages/Account/Card/AccountMailAlias.vue @@ -61,23 +61,15 @@ const fetchAccountExistence = async () => { }; const deleteMailAlias = async (row) => { - try { - await axios.delete(`${urlPath}/${row.id}`); - fetchMailAliases(); - notify(t('Unsubscribed from alias!'), 'positive'); - } catch (error) { - console.error(error); - } + await axios.delete(`${urlPath}/${row.id}`); + fetchMailAliases(); + notify(t('Unsubscribed from alias!'), 'positive'); }; const createMailAlias = async (mailAliasFormData) => { - try { - await axios.post(urlPath, mailAliasFormData); - notify(t('Subscribed to alias!'), 'positive'); - fetchMailAliases(); - } catch (error) { - console.error(error); - } + await axios.post(urlPath, mailAliasFormData); + notify(t('Subscribed to alias!'), 'positive'); + fetchMailAliases(); }; const fetchMailAliases = async () => { diff --git a/src/pages/Account/Role/Card/SubRoles.vue b/src/pages/Account/Role/Card/SubRoles.vue index d17f96dd8..6cac94667 100644 --- a/src/pages/Account/Role/Card/SubRoles.vue +++ b/src/pages/Account/Role/Card/SubRoles.vue @@ -46,29 +46,15 @@ const columns = computed(() => [ ]); const deleteSubRole = async (row) => { - try { - await axios.delete(`${urlPath.value}/${row.id}`); - fetchSubRoles(); - notify( - t('Role removed. Changes will take a while to fully propagate.'), - 'positive' - ); - } catch (error) { - console.error(error); - } + await axios.delete(`${urlPath.value}/${row.id}`); + fetchSubRoles(); + notify(t('Role removed. Changes will take a while to fully propagate.'), 'positive'); }; const createSubRole = async (subRoleFormData) => { - try { - await axios.post(urlPath.value, subRoleFormData); - notify( - t('Role added! Changes will take a while to fully propagate.'), - 'positive' - ); - fetchSubRoles(); - } catch (error) { - console.error(error); - } + await axios.post(urlPath.value, subRoleFormData); + notify(t('Role added! Changes will take a while to fully propagate.'), 'positive'); + fetchSubRoles(); }; watch( diff --git a/src/pages/Ticket/Card/BasicData/TicketBasicDataForm.vue b/src/pages/Ticket/Card/BasicData/TicketBasicDataForm.vue index f5ce8a0f3..f6c20c514 100644 --- a/src/pages/Ticket/Card/BasicData/TicketBasicDataForm.vue +++ b/src/pages/Ticket/Card/BasicData/TicketBasicDataForm.vue @@ -112,32 +112,20 @@ const getShipped = async (params) => { }; const onChangeZone = async (zoneId) => { - try { - formData.value.agencyModeFk = null; - const { data } = await axios.get(`Zones/${zoneId}`); - formData.value.agencyModeFk = data.agencyModeFk; - } catch (error) { - console.error(error); - } + formData.value.agencyModeFk = null; + const { data } = await axios.get(`Zones/${zoneId}`); + formData.value.agencyModeFk = data.agencyModeFk; }; const onChangeAddress = async (addressId) => { - try { - formData.value.nickname = null; - const { data } = await axios.get(`Addresses/${addressId}`); - formData.value.nickname = data.nickname; - } catch (error) { - console.error(error); - } + formData.value.nickname = null; + const { data } = await axios.get(`Addresses/${addressId}`); + formData.value.nickname = data.nickname; }; const getClientDefaultAddress = async (clientId) => { - try { - const { data } = await axios.get(`Clients/${clientId}`); - if (data) addressId.value = data.defaultAddressFk; - } catch (error) { - console.error(error); - } + const { data } = await axios.get(`Clients/${clientId}`); + if (data) addressId.value = data.defaultAddressFk; }; const clientAddressesList = async (value) => { diff --git a/src/pages/Ticket/Card/BasicData/TicketBasicDataView.vue b/src/pages/Ticket/Card/BasicData/TicketBasicDataView.vue index 92640f898..fb7881403 100644 --- a/src/pages/Ticket/Card/BasicData/TicketBasicDataView.vue +++ b/src/pages/Ticket/Card/BasicData/TicketBasicDataView.vue @@ -70,60 +70,51 @@ const isFormInvalid = () => { }; const getPriceDifference = async () => { - try { - const params = { - landed: formData.value.landed, - addressId: formData.value.addressFk, - agencyModeId: formData.value.agencyModeFk, - zoneId: formData.value.zoneFk, - warehouseId: formData.value.warehouseFk, - shipped: formData.value.shipped, - }; - const { data } = await axios.post( - `tickets/${formData.value.id}/priceDifference`, - params - ); - formData.value.sale = data; - } catch (error) { - console.error(error); - } + const params = { + landed: formData.value.landed, + addressId: formData.value.addressFk, + agencyModeId: formData.value.agencyModeFk, + zoneId: formData.value.zoneFk, + warehouseId: formData.value.warehouseFk, + shipped: formData.value.shipped, + }; + const { data } = await axios.post( + `tickets/${formData.value.id}/priceDifference`, + params + ); + formData.value.sale = data; }; const submit = async () => { - try { - if (!formData.value.option) - return notify(t('basicData.chooseAnOption'), 'negative'); + if (!formData.value.option) return notify(t('basicData.chooseAnOption'), 'negative'); - const params = { - clientFk: formData.value.clientFk, - nickname: formData.value.nickname, - agencyModeFk: formData.value.agencyModeFk, - addressFk: formData.value.addressFk, - zoneFk: formData.value.zoneFk, - warehouseFk: formData.value.warehouseFk, - companyFk: formData.value.companyFk, - shipped: formData.value.shipped, - landed: formData.value.landed, - isDeleted: formData.value.isDeleted, - option: formData.value.option, - isWithoutNegatives: formData.value.withoutNegatives, - withWarningAccept: formData.value.withWarningAccept, - keepPrice: false, - }; + const params = { + clientFk: formData.value.clientFk, + nickname: formData.value.nickname, + agencyModeFk: formData.value.agencyModeFk, + addressFk: formData.value.addressFk, + zoneFk: formData.value.zoneFk, + warehouseFk: formData.value.warehouseFk, + companyFk: formData.value.companyFk, + shipped: formData.value.shipped, + landed: formData.value.landed, + isDeleted: formData.value.isDeleted, + option: formData.value.option, + isWithoutNegatives: formData.value.withoutNegatives, + withWarningAccept: formData.value.withWarningAccept, + keepPrice: false, + }; - const { data } = await axios.post( - `tickets/${formData.value.id}/componentUpdate`, - params - ); + const { data } = await axios.post( + `tickets/${formData.value.id}/componentUpdate`, + params + ); - if (!data) return; + if (!data) return; - const ticketToMove = data.id; - notify(t('basicData.unroutedTicket'), 'positive'); - router.push({ name: 'TicketSummary', params: { id: ticketToMove } }); - } catch (error) { - console.error(error); - } + const ticketToMove = data.id; + notify(t('basicData.unroutedTicket'), 'positive'); + router.push({ name: 'TicketSummary', params: { id: ticketToMove } }); }; const submitWithNegatives = async () => { diff --git a/src/pages/Ticket/Card/ExpeditionNewTicket.vue b/src/pages/Ticket/Card/ExpeditionNewTicket.vue index 9183ae405..c288f6cc2 100644 --- a/src/pages/Ticket/Card/ExpeditionNewTicket.vue +++ b/src/pages/Ticket/Card/ExpeditionNewTicket.vue @@ -34,26 +34,20 @@ const newTicketFormData = reactive({}); const date = new Date(); const createTicket = async () => { - try { - const expeditionIds = $props.selectedExpeditions.map( - (expedition) => expedition.id - ); - const params = { - clientId: $props.ticket.clientFk, - landed: newTicketFormData.landed, - warehouseId: $props.ticket.warehouseFk, - addressId: $props.ticket.addressFk, - agencyModeId: $props.ticket.agencyModeFk, - routeId: newTicketFormData.routeFk, - expeditionIds: expeditionIds, - }; + const expeditionIds = $props.selectedExpeditions.map((expedition) => expedition.id); + const params = { + clientId: $props.ticket.clientFk, + landed: newTicketFormData.landed, + warehouseId: $props.ticket.warehouseFk, + addressId: $props.ticket.addressFk, + agencyModeId: $props.ticket.agencyModeFk, + routeId: newTicketFormData.routeFk, + expeditionIds: expeditionIds, + }; - const { data } = await axios.post('Expeditions/moveExpeditions', params); - notify(t('globals.dataSaved'), 'positive'); - router.push({ name: 'TicketSummary', params: { id: data.id } }); - } catch (error) { - console.error(error); - } + const { data } = await axios.post('Expeditions/moveExpeditions', params); + notify(t('globals.dataSaved'), 'positive'); + router.push({ name: 'TicketSummary', params: { id: data.id } }); }; diff --git a/src/pages/Ticket/Card/TicketComponents.vue b/src/pages/Ticket/Card/TicketComponents.vue index 0bccdaacd..b5b3c430c 100644 --- a/src/pages/Ticket/Card/TicketComponents.vue +++ b/src/pages/Ticket/Card/TicketComponents.vue @@ -150,31 +150,19 @@ const getTotal = computed(() => { }); const getComponentsSum = async () => { - try { - const { data } = await axios.get(`Tickets/${route.params.id}/getComponentsSum`); - componentsList.value = data; - } catch (error) { - console.error(error); - } + const { data } = await axios.get(`Tickets/${route.params.id}/getComponentsSum`); + componentsList.value = data; }; const getTheoricalCost = async () => { - try { - const { data } = await axios.get(`Tickets/${route.params.id}/freightCost`); - theoricalCost.value = data; - } catch (error) { - console.error(error); - } + const { data } = await axios.get(`Tickets/${route.params.id}/freightCost`); + theoricalCost.value = data; }; const getTicketVolume = async () => { - try { - if (!ticketData.value) return; - const { data } = await axios.get(`Tickets/${ticketData.value.id}/getVolume`); - ticketVolume.value = data[0].volume; - } catch (error) { - console.error(error); - } + if (!ticketData.value) return; + const { data } = await axios.get(`Tickets/${ticketData.value.id}/getVolume`); + ticketVolume.value = data[0].volume; }; onMounted(() => { diff --git a/src/pages/Ticket/Card/TicketExpedition.vue b/src/pages/Ticket/Card/TicketExpedition.vue index 4becb3db3..b4a2ca732 100644 --- a/src/pages/Ticket/Card/TicketExpedition.vue +++ b/src/pages/Ticket/Card/TicketExpedition.vue @@ -187,18 +187,12 @@ const showNewTicketDialog = (withRoute = false) => { }; const deleteExpedition = async () => { - try { - const expeditionIds = selectedExpeditions.value.map( - (expedition) => expedition.id - ); - const params = { expeditionIds }; - await axios.post('Expeditions/deleteExpeditions', params); - await refetchExpeditions(); - selectedExpeditions.value = []; - notify(t('expedition.expeditionRemoved'), 'positive'); - } catch (error) { - console.error(error); - } + const expeditionIds = selectedExpeditions.value.map((expedition) => expedition.id); + const params = { expeditionIds }; + await axios.post('Expeditions/deleteExpeditions', params); + await refetchExpeditions(); + selectedExpeditions.value = []; + notify(t('expedition.expeditionRemoved'), 'positive'); }; const showLog = async (expedition) => { @@ -207,29 +201,25 @@ const showLog = async (expedition) => { }; const getExpeditionState = async (expedition) => { - try { - const filter = { - where: { expeditionFk: expedition.id }, - order: ['created DESC'], + const filter = { + where: { expeditionFk: expedition.id }, + order: ['created DESC'], + }; + + const { data: expeditionStates } = await axios.get(`ExpeditionStates/filter`, { + params: { filter: JSON.stringify(filter) }, + }); + const { data: scannedStates } = await axios.get(`ExpeditionStates`, { + params: { filter: JSON.stringify(filter), fields: ['id', 'isScanned'] }, + }); + + expeditionsLogsData.value = expeditionStates.map((state) => { + const scannedState = scannedStates.find((s) => s.id === state.id); + return { + ...state, + isScanned: scannedState ? scannedState.isScanned : false, }; - - const { data: expeditionStates } = await axios.get(`ExpeditionStates/filter`, { - params: { filter: JSON.stringify(filter) }, - }); - const { data: scannedStates } = await axios.get(`ExpeditionStates`, { - params: { filter: JSON.stringify(filter), fields: ['id', 'isScanned'] }, - }); - - expeditionsLogsData.value = expeditionStates.map((state) => { - const scannedState = scannedStates.find((s) => s.id === state.id); - return { - ...state, - isScanned: scannedState ? scannedState.isScanned : false, - }; - }); - } catch (error) { - console.error(error); - } + }); }; onMounted(async () => { diff --git a/src/pages/Ticket/Card/TicketSaleMoreActions.vue b/src/pages/Ticket/Card/TicketSaleMoreActions.vue index 2ec519d2d..588f78a7b 100644 --- a/src/pages/Ticket/Card/TicketSaleMoreActions.vue +++ b/src/pages/Ticket/Card/TicketSaleMoreActions.vue @@ -165,14 +165,10 @@ const createRefund = async (withWarehouse) => { negative: true, }; - try { - const { data } = await axios.post('Tickets/cloneAll', params); - const [refundTicket] = data; - notify(t('refundTicketCreated', { ticketId: refundTicket.id }), 'positive'); - push({ name: 'TicketSale', params: { id: refundTicket.id } }); - } catch (error) { - console.error(error); - } + const { data } = await axios.post('Tickets/cloneAll', params); + const [refundTicket] = data; + notify(t('refundTicketCreated', { ticketId: refundTicket.id }), 'positive'); + push({ name: 'TicketSale', params: { id: refundTicket.id } }); }; diff --git a/src/pages/Ticket/Card/TicketSaleTracking.vue b/src/pages/Ticket/Card/TicketSaleTracking.vue index e7830bf37..1083393c4 100644 --- a/src/pages/Ticket/Card/TicketSaleTracking.vue +++ b/src/pages/Ticket/Card/TicketSaleTracking.vue @@ -150,18 +150,14 @@ const shelvingsTableColumns = computed(() => [ ]); const getSaleTrackings = async (sale) => { - try { - const filter = { - where: { saleFk: sale.saleFk }, - order: ['itemFk DESC'], - }; - const { data } = await axios.get(`SaleTrackings/listSaleTracking`, { - params: { filter: JSON.stringify(filter) }, - }); - saleTrackings.value = data; - } catch (error) { - console.error(error); - } + const filter = { + where: { saleFk: sale.saleFk }, + order: ['itemFk DESC'], + }; + const { data } = await axios.get(`SaleTrackings/listSaleTracking`, { + params: { filter: JSON.stringify(filter) }, + }); + saleTrackings.value = data; }; const showLog = async (sale) => { @@ -170,17 +166,13 @@ const showLog = async (sale) => { }; const getItemShelvingSales = async (sale) => { - try { - const filter = { - where: { saleFk: sale.saleFk }, - }; - const { data } = await axios.get(`ItemShelvingSales/filter`, { - params: { filter: JSON.stringify(filter) }, - }); - itemShelvingsSales.value = data; - } catch (error) { - console.error(error); - } + const filter = { + where: { saleFk: sale.saleFk }, + }; + const { data } = await axios.get(`ItemShelvingSales/filter`, { + params: { filter: JSON.stringify(filter) }, + }); + itemShelvingsSales.value = data; }; const showShelving = async (sale) => { @@ -189,36 +181,28 @@ const showShelving = async (sale) => { }; const updateQuantity = async (sale) => { - try { - if (oldQuantity.value === sale.quantity) return; - const params = { - quantity: sale.quantity, - }; - await axios.patch(`ItemShelvingSales/${sale.id}`, params); - oldQuantity.value = null; - } catch (error) { - console.error(error); - } + if (oldQuantity.value === sale.quantity) return; + const params = { + quantity: sale.quantity, + }; + await axios.patch(`ItemShelvingSales/${sale.id}`, params); + oldQuantity.value = null; }; const updateParking = async (sale) => { - try { - const filter = { - fields: ['id'], - where: { - code: sale.shelvingFk, - }, - }; - const { data } = await axios.get(`Shelvings/findOne`, { - params: { filter: JSON.stringify(filter) }, - }); - const params = { - parkingFk: sale.parkingFk, - }; - await axios.patch(`Shelvings/${data.id}`, params); - } catch (error) { - console.error(error); - } + const filter = { + fields: ['id'], + where: { + code: sale.shelvingFk, + }, + }; + const { data } = await axios.get(`Shelvings/findOne`, { + params: { filter: JSON.stringify(filter) }, + }); + const params = { + parkingFk: sale.parkingFk, + }; + await axios.patch(`Shelvings/${data.id}`, params); }; const updateShelving = async (sale) => { @@ -241,61 +225,41 @@ const updateShelving = async (sale) => { }; const saleTrackingNew = async (sale, stateCode, isChecked) => { - try { - const params = { - saleFk: sale.saleFk, - isChecked, - quantity: sale.quantity, - stateCode, - }; - await axios.post(`SaleTrackings/new`, params); - notify(t('globals.dataSaved'), 'positive'); - } catch (error) { - console.error(error); - } + const params = { + saleFk: sale.saleFk, + isChecked, + quantity: sale.quantity, + stateCode, + }; + await axios.post(`SaleTrackings/new`, params); + notify(t('globals.dataSaved'), 'positive'); }; const saleTrackingDel = async ({ saleFk }, stateCode) => { - try { - const params = { - saleFk, - stateCodes: [stateCode], - }; - await axios.post(`SaleTrackings/delete`, params); - notify(t('globals.dataSaved'), 'positive'); - } catch (error) { - console.error(error); - } + const params = { + saleFk, + stateCodes: [stateCode], + }; + await axios.post(`SaleTrackings/delete`, params); + notify(t('globals.dataSaved'), 'positive'); }; const clickSaleGroupDetail = async (sale) => { - try { - if (!sale.saleGroupDetailFk) return; + if (!sale.saleGroupDetailFk) return; - await axios.delete(`SaleGroupDetails/${sale.saleGroupDetailFk}`); - sale.hasSaleGroupDetail = false; - notify(t('globals.dataSaved'), 'positive'); - } catch (error) { - console.error(error); - } + await axios.delete(`SaleGroupDetails/${sale.saleGroupDetailFk}`); + sale.hasSaleGroupDetail = false; + notify(t('globals.dataSaved'), 'positive'); }; const clickPreviousSelected = (sale) => { - try { - qCheckBoxController(sale, 'isPreviousSelected'); - if (!sale.isPreviousSelected) sale.isPrevious = false; - } catch (error) { - console.error(error); - } + qCheckBoxController(sale, 'isPreviousSelected'); + if (!sale.isPreviousSelected) sale.isPrevious = false; }; const clickPrevious = (sale) => { - try { - qCheckBoxController(sale, 'isPrevious'); - if (sale.isPrevious) sale.isPreviousSelected = true; - } catch (error) { - console.error(error); - } + qCheckBoxController(sale, 'isPrevious'); + if (sale.isPrevious) sale.isPreviousSelected = true; }; const qCheckBoxController = (sale, action) => { @@ -306,16 +270,12 @@ const qCheckBoxController = (sale, action) => { isPreviousSelected: 'PREVIOUS_PREPARATION', }; const stateCode = STATE_CODES[action]; - try { - if (!sale[action]) { - saleTrackingNew(sale, stateCode, true); - sale[action] = true; - } else { - saleTrackingDel(sale, stateCode); - sale[action] = false; - } - } catch (error) { - console.error(error); + if (!sale[action]) { + saleTrackingNew(sale, stateCode, true); + sale[action] = true; + } else { + saleTrackingDel(sale, stateCode); + sale[action] = false; } }; diff --git a/src/pages/Ticket/Card/TicketService.vue b/src/pages/Ticket/Card/TicketService.vue index 45a870f7f..47c28a422 100644 --- a/src/pages/Ticket/Card/TicketService.vue +++ b/src/pages/Ticket/Card/TicketService.vue @@ -46,40 +46,32 @@ watch( onMounted(async () => await getDefaultTaxClass()); const createRefund = async () => { - try { - if (!selected.value.length) return; + if (!selected.value.length) return; - const params = { - servicesIds: selected.value.map((s) => +s.id), - withWarehouse: false, - negative: true, - }; - const { data } = await axios.post('Sales/clone', params); - const [refundTicket] = data; - notify( - t('service.createRefundSuccess', { - ticketId: refundTicket.id, - }), - 'positive' - ); - router.push({ name: 'TicketSale', params: { id: refundTicket.id } }); - } catch (error) { - console.error(error); - } + const params = { + servicesIds: selected.value.map((s) => +s.id), + withWarehouse: false, + negative: true, + }; + const { data } = await axios.post('Sales/clone', params); + const [refundTicket] = data; + notify( + t('service.createRefundSuccess', { + ticketId: refundTicket.id, + }), + 'positive' + ); + router.push({ name: 'TicketSale', params: { id: refundTicket.id } }); }; const getDefaultTaxClass = async () => { - try { - let filter = { - where: { code: 'G' }, - }; - const { data } = await axios.get('TaxClasses/findOne', { - params: { filter: JSON.stringify(filter) }, - }); - defaultTaxClass.value = data; - } catch (error) { - console.error(error); - } + let filter = { + where: { code: 'G' }, + }; + const { data } = await axios.get('TaxClasses/findOne', { + params: { filter: JSON.stringify(filter) }, + }); + defaultTaxClass.value = data; }; const columns = computed(() => [ diff --git a/src/pages/Ticket/Card/TicketVolume.vue b/src/pages/Ticket/Card/TicketVolume.vue index 2cf7ffc42..edfe489d9 100644 --- a/src/pages/Ticket/Card/TicketVolume.vue +++ b/src/pages/Ticket/Card/TicketVolume.vue @@ -75,22 +75,18 @@ const columns = computed(() => [ ]); const applyVolumes = async (salesData) => { - try { - if (!salesData.length) return; + if (!salesData.length) return; - sales.value = salesData; - const ticket = sales.value[0].ticketFk; - const { data } = await axios.get(`Tickets/${ticket}/getVolume`); - const volumes = new Map(data.saleVolume.map((volume) => [volume.saleFk, volume])); + sales.value = salesData; + const ticket = sales.value[0].ticketFk; + const { data } = await axios.get(`Tickets/${ticket}/getVolume`); + const volumes = new Map(data.saleVolume.map((volume) => [volume.saleFk, volume])); - sales.value.forEach((sale) => { - sale.saleVolume = volumes.get(sale.id); - }); + sales.value.forEach((sale) => { + sale.saleVolume = volumes.get(sale.id); + }); - packingTypeVolume.value = data.packingTypeVolume; - } catch (error) { - console.error(error); - } + packingTypeVolume.value = data.packingTypeVolume; }; onMounted(() => (stateStore.rightDrawer = true)); diff --git a/src/pages/Ticket/TicketAdvanceFilter.vue b/src/pages/Ticket/TicketAdvanceFilter.vue index b25ebdea6..27cacd80a 100644 --- a/src/pages/Ticket/TicketAdvanceFilter.vue +++ b/src/pages/Ticket/TicketAdvanceFilter.vue @@ -27,20 +27,16 @@ const warehousesOptions = ref([]); const itemPackingTypes = ref([]); const getItemPackingTypes = async () => { - try { - const filter = { - where: { isActive: true }, - }; - const { data } = await axios.get('ItemPackingTypes', { - params: { filter: JSON.stringify(filter) }, - }); - itemPackingTypes.value = data.map((ipt) => ({ - description: t(ipt.description), - code: ipt.code, - })); - } catch (error) { - console.error(error); - } + const filter = { + where: { isActive: true }, + }; + const { data } = await axios.get('ItemPackingTypes', { + params: { filter: JSON.stringify(filter) }, + }); + itemPackingTypes.value = data.map((ipt) => ({ + description: t(ipt.description), + code: ipt.code, + })); }; onMounted(async () => await getItemPackingTypes()); diff --git a/src/pages/Ticket/TicketFutureFilter.vue b/src/pages/Ticket/TicketFutureFilter.vue index 6345f62b3..ffe967272 100644 --- a/src/pages/Ticket/TicketFutureFilter.vue +++ b/src/pages/Ticket/TicketFutureFilter.vue @@ -24,33 +24,25 @@ const itemPackingTypes = ref([]); const stateOptions = ref([]); const getItemPackingTypes = async () => { - try { - const filter = { - where: { isActive: true }, - }; - const { data } = await axios.get('ItemPackingTypes', { - params: { filter: JSON.stringify(filter) }, - }); - itemPackingTypes.value = data.map((ipt) => ({ - description: t(ipt.description), - code: ipt.code, - })); - } catch (error) { - console.error(error); - } + const filter = { + where: { isActive: true }, + }; + const { data } = await axios.get('ItemPackingTypes', { + params: { filter: JSON.stringify(filter) }, + }); + itemPackingTypes.value = data.map((ipt) => ({ + description: t(ipt.description), + code: ipt.code, + })); }; const getGroupedStates = async () => { - try { - const { data } = await axios.get('AlertLevels'); - stateOptions.value = data.map((state) => ({ - id: state.id, - name: t(`futureTickets.${state.code}`), - code: state.code, - })); - } catch (error) { - console.error(error); - } + const { data } = await axios.get('AlertLevels'); + stateOptions.value = data.map((state) => ({ + id: state.id, + name: t(`futureTickets.${state.code}`), + code: state.code, + })); }; onMounted(async () => { From ee31bc8262d511bc659316d7046b5f9d0228034d Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 22 Oct 2024 14:07:27 +0200 Subject: [PATCH 10/17] chore: refs #8039 not required --- src/boot/axios.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/boot/axios.js b/src/boot/axios.js index b084b835d..aee38e887 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -3,7 +3,6 @@ import { useSession } from 'src/composables/useSession'; import { Router } from 'src/router'; import useNotify from 'src/composables/useNotify.js'; import { useStateQueryStore } from 'src/stores/useStateQueryStore'; -import { CanceledError } from 'axios'; const session = useSession(); const { notify } = useNotify(); From 6f57d9e4906f7c74b50545a3271574b942efeac4 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 24 Oct 2024 10:21:25 +0200 Subject: [PATCH 11/17] refactor: refs #7524 use VnTable --- src/components/VnTable/VnTable.vue | 6 +- src/pages/Ticket/TicketAdvance.vue | 605 +++++++++-------------- src/pages/Ticket/TicketAdvanceFilter.vue | 3 + 3 files changed, 234 insertions(+), 380 deletions(-) diff --git a/src/components/VnTable/VnTable.vue b/src/components/VnTable/VnTable.vue index 9209eaf7b..0afc5e8cf 100644 --- a/src/components/VnTable/VnTable.vue +++ b/src/components/VnTable/VnTable.vue @@ -447,7 +447,11 @@ function handleOnDataSaved(_) { />