From d3130f12f3e397058266185c4ad37c5e5891d394 Mon Sep 17 00:00:00 2001 From: taro Date: Wed, 2 Apr 2025 11:31:21 -0300 Subject: [PATCH] refactor(CheckoutView): use salix for checkOrder --- src/i18n/ca-ES/index.js | 3 ++- src/i18n/en-US/index.js | 3 ++- src/i18n/es-ES/index.js | 3 ++- src/i18n/fr-FR/index.js | 3 ++- src/i18n/pt-PT/index.js | 3 ++- src/stores/app.js | 57 ++++++++++++++++++++++------------------- 6 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/i18n/ca-ES/index.js b/src/i18n/ca-ES/index.js index 48d214e0..02f060ea 100644 --- a/src/i18n/ca-ES/index.js +++ b/src/i18n/ca-ES/index.js @@ -168,6 +168,7 @@ export default { // Errors errors: { statusUnauthorized: 'Accés denegat', - tokenConfig: 'Error al obtenir la configuració del token' + tokenConfig: 'Error al obtenir la configuració del token', + orderNotOwnedByUser: 'The order belongs to another user' } }; diff --git a/src/i18n/en-US/index.js b/src/i18n/en-US/index.js index 80107dd5..fba57ab0 100644 --- a/src/i18n/en-US/index.js +++ b/src/i18n/en-US/index.js @@ -200,6 +200,7 @@ export default { // Errors errors: { statusUnauthorized: 'Access denied', - tokenConfig: 'Error fetching token config' + tokenConfig: 'Error fetching token config', + orderNotOwnedByUser: 'The order belongs to another user' } }; diff --git a/src/i18n/es-ES/index.js b/src/i18n/es-ES/index.js index 15639c2d..67248e94 100644 --- a/src/i18n/es-ES/index.js +++ b/src/i18n/es-ES/index.js @@ -200,6 +200,7 @@ export default { // Errors errors: { statusUnauthorized: 'Acceso denegado', - tokenConfig: 'Error al obtener configuración de token' + tokenConfig: 'Error al obtener configuración de token', + orderNotOwnedByUser: 'The order belongs to another user' } }; diff --git a/src/i18n/fr-FR/index.js b/src/i18n/fr-FR/index.js index 2eea9a38..9881c440 100644 --- a/src/i18n/fr-FR/index.js +++ b/src/i18n/fr-FR/index.js @@ -172,6 +172,7 @@ export default { errors: { statusUnauthorized: 'Accès refusé', tokenConfig: - 'Erreur lors de la récupération de la configuration du jeton' + 'Erreur lors de la récupération de la configuration du jeton', + orderNotOwnedByUser: 'The order belongs to another user' } }; diff --git a/src/i18n/pt-PT/index.js b/src/i18n/pt-PT/index.js index 460335e0..ecbed192 100644 --- a/src/i18n/pt-PT/index.js +++ b/src/i18n/pt-PT/index.js @@ -166,6 +166,7 @@ export default { // Errors errors: { statusUnauthorized: 'Acesso negado', - tokenConfig: 'Erro ao obter configuração do token' + tokenConfig: 'Erro ao obter configuração do token', + orderNotOwnedByUser: 'The order belongs to another user' } }; diff --git a/src/stores/app.js b/src/stores/app.js index d5183dc8..35e9bc84 100644 --- a/src/stores/app.js +++ b/src/stores/app.js @@ -81,14 +81,6 @@ export const useAppStore = defineStore('hedera', { this.basketOrderId = localStorage.getItem(storageOrderName); }, - async checkOrder(orderId) { - const resultSet = await jApi.execQuery( - 'CALL myOrder_checkConfig(#id)', - { id: orderId } - ); - resultSet.fetchValue(); - }, - async check(checkoutContinue) { if (this.basketOrderId) { return await this.checkRedirect(checkoutContinue); @@ -99,26 +91,37 @@ export const useAppStore = defineStore('hedera', { }, async checkRedirect(checkoutContinue) { - try { - await this.checkOrder(this.basketOrderId); - return true; - } catch (err) { - switch (err.code) { - case 'orderConfirmed': - case 'orderNotOwnedByUser': - this.unloadOrder(); - await this.redirect(); - break; - default: - this.router.push({ - name: 'checkout', - params: { id: this.basketOrderId }, - query: { continue: checkoutContinue } - }); - notify(err.message, 'negative'); - } - return false; + const orderId = this.basketOrderId; + // const orderId = 'nope!'; + const myOrder_checkConfig = await api.post('applications/myOrder_checkConfig/execute-proc', { + schema: 'hedera', + params: [orderId], + }, { + validateStatus: () => true, + }); + + if (myOrder_checkConfig.status >= 200 && myOrder_checkConfig.status < 300) { + return true; } + + switch (myOrder_checkConfig.data.error?.message) { + case 'orderNotOwnedByUser': + notify(t(`errors.orderNotOwnedByUser`), 'negative'); + case 'orderConfirmed': + case 'orderNotOwnedByUser': + this.unloadOrder(); + await this.redirect(); + break; + default: + this.router.push({ + name: 'checkout', + params: { id: this.basketOrderId }, + query: { continue: checkoutContinue } + }); + notify(myOrder_checkConfig.data.error.message, 'negative'); + } + + return false; }, async redirect() {