Merge pull request 'fix: migrate pending orders' (!121) from ldragan/hedera-web:taro/pending-orders into beta
gitea/hedera-web/pipeline/head This commit looks good Details

Reviewed-on: #121
Reviewed-by: Javier Segarra <jsegarra@verdnatura.es>
This commit is contained in:
Javier Segarra 2025-03-27 05:15:03 +00:00
commit bae2de2478
3 changed files with 71 additions and 26 deletions

View File

@ -1,2 +1,5 @@
debian
node_modules
node_modules
.quasar
build
.vscode

View File

@ -1,5 +1,5 @@
<script setup>
import { ref, inject, onMounted } from 'vue';
import { ref, inject } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
@ -11,8 +11,10 @@ import { useVnConfirm } from 'src/composables/useVnConfirm.js';
import useNotify from 'src/composables/useNotify.js';
import { useAppStore } from 'stores/app';
import { storeToRefs } from 'pinia';
import { onUserId } from 'src/utils/onUserId';
const jApi = inject('jApi');
const api = inject('api');
const { t } = useI18n();
const { openConfirmationModal } = useVnConfirm();
const { notify } = useNotify();
@ -23,18 +25,48 @@ const router = useRouter();
const loading = ref(false);
const orders = ref([]);
const getOrders = async () => {
const getOrders = async (clientFk) => {
try {
loading.value = true;
orders.value = await jApi.query(
`SELECT o.id, o.sent, o.deliveryMethodFk, o.taxableBase,
a.nickname, am.description agency
FROM myOrder o
JOIN myAddress a ON a.id = o.addressFk
JOIN vn.agencyMode am ON am.id = o.agencyModeFk
WHERE NOT o.isConfirmed
ORDER BY o.sent DESC`
);
const filter = {
where: {
clientFk,
isConfirmed: false,
source_app: 'WEB',
},
include: [
{
relation: 'address',
scope: {
fields: ['nickname', 'city'],
}
},
{
relation: 'agencyMode',
scope: {
fields: ['description'],
}
},
],
fields: [
'id',
'landed',
'delivery_method_id',
'taxableBase',
'addressFk',
'agencyModeFk'
]
};
const { data: salixOrders } = await api.get('Orders', {
params: {
filter: JSON.stringify(filter)
}
});
orders.value = salixOrders;
loading.value = false;
} catch (error) {
console.error('Error getting orders:', error);
@ -43,14 +75,7 @@ const getOrders = async () => {
const removeOrder = async (id, index) => {
try {
await jApi.execQuery(
`START TRANSACTION;
DELETE FROM hedera.myOrder WHERE ((id = #id));
COMMIT`,
{
id
}
);
await api.delete(`Orders/${id}`);
orders.value.splice(index, 1);
notify(t('dataSaved'), 'positive');
} catch (error) {
@ -63,9 +88,8 @@ const loadOrder = orderId => {
router.push({ name: 'catalog' });
};
onMounted(async () => {
getOrders();
});
onUserId(getOrders);
</script>
<template>
@ -93,11 +117,11 @@ onMounted(async () => {
>
<template #content>
<QItemLabel class="text-bold q-mb-sm">
{{ formatDateTitle(order.sent) }}
{{ formatDateTitle(order.landed) }}
</QItemLabel>
<QItemLabel> #{{ order.id }} </QItemLabel>
<QItemLabel>{{ order.nickname }}</QItemLabel>
<QItemLabel>{{ order.agency }}</QItemLabel>
<QItemLabel>{{ order.address.nickname }}</QItemLabel>
<QItemLabel>{{ order.agencyMode.description }}</QItemLabel>
<QItemLabel>{{ currency(order.taxableBase) }}</QItemLabel>
</template>
<template #actions>

18
src/utils/onUserId.js Normal file
View File

@ -0,0 +1,18 @@
import { watch } from 'vue';
import { useUserStore } from 'stores/user';
const userStore = useUserStore();
export const onUserId = (cb) => watch(
() => userStore?.user?.id,
async userId => {
if (!userId) return;
try {
await cb(userId);
} catch (error) {
console.error(error);
}
},
{ immediate: true }
);