Merge pull request 'refactor: use Salix in app.js for `hasOrders`' (!157) from ldragan/hedera-web:taro/salix-appjs-has-orders into beta
gitea/hedera-web/pipeline/head There was a failure building this commit Details

Reviewed-on: #157
Reviewed-by: Javier Segarra <jsegarra@verdnatura.es>
This commit is contained in:
Javier Segarra 2025-05-06 06:39:35 +00:00
commit 5dad9ee951
1 changed files with 26 additions and 5 deletions

View File

@ -1,5 +1,5 @@
import { defineStore } from 'pinia';
import { jApi, api } from '@/boot/axios';
import { api } from '@/boot/axios';
import useNotify from '@/composables/useNotify.js';
import { i18n } from '@/boot/i18n';
import { useQuasar } from 'quasar';
@ -8,6 +8,29 @@ const { notify } = useNotify();
const storageOrderName = 'hederaBasket';
const { t } = i18n.global;
const userHasOrders = async () => {
try {
const filter = {
where: {
isConfirmed: false,
source_app: 'WEB'
},
fields: ['id'],
limit: 1,
};
const { data: salixOrders } = await api.get('Orders', {
params: {
filter: JSON.stringify(filter)
}
});
return !!salixOrders?.length;
} catch (error) {
console.error('Error getting orders:', error);
}
};
export const useAppStore = defineStore('hedera', {
state: () => ({
customTitle: null,
@ -130,10 +153,8 @@ export const useAppStore = defineStore('hedera', {
},
async redirect() {
const resultSet = await jApi.execQuery(
'SELECT COUNT(*) > 0 FROM myOrder'
);
if (resultSet.fetchValue()) {
const hasOrders = await userHasOrders();
if (hasOrders) {
this.router.push({ name: 'pendingOrders' });
notify('loadAnOrder', 'warning');
} else {