refactor(CheckoutView): use salix for createOrder
gitea/hedera-web/pipeline/pr-beta This commit looks good Details

This commit is contained in:
taro 2025-04-04 03:20:33 -03:00
parent 410bf86913
commit f5e17900d7
1 changed files with 32 additions and 17 deletions

View File

@ -8,6 +8,7 @@ import VnSelect from 'src/components/common/VnSelect.vue';
import { formatDateTitle, formatDate } from 'src/lib/filters.js'; import { formatDateTitle, formatDate } from 'src/lib/filters.js';
import useNotify from 'src/composables/useNotify.js'; import useNotify from 'src/composables/useNotify.js';
import { onUserId } from 'src/utils/onUserId'; import { onUserId } from 'src/utils/onUserId';
import { useUserStore } from 'stores/user';
import { useAppStore } from 'stores/app'; import { useAppStore } from 'stores/app';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
@ -18,6 +19,7 @@ const route = useRoute();
const router = useRouter(); const router = useRouter();
const { notify } = useNotify(); const { notify } = useNotify();
const appStore = useAppStore(); const appStore = useAppStore();
const userStore = useUserStore();
const { localeDates, isMobile } = storeToRefs(appStore); const { localeDates, isMobile } = storeToRefs(appStore);
const stepperRef = ref(null); const stepperRef = ref(null);
@ -299,30 +301,43 @@ const onPreviousStep = async stepIndex => {
const submit = async () => { const submit = async () => {
loading.value = true; loading.value = true;
let query =
'CALL myOrder_create(@orderId, #date, #method, #agency, #address); SELECT @orderId;'; const userId = userStore?.user?.id;
if (id) {
orderForm.value.id = id; if (!userId) {
query = throw 'no user id';
'CALL myOrder_configure(#id, #date, #method, #agency, #address)';
} }
let resultSet;
try { try {
const { date, ...restOfForm } = orderForm.value; const { date, ...restOfForm } = orderForm.value;
const _date = new Date(date); const _date = new Date(date);
resultSet = await jApi.execQuery(query, { ...restOfForm, date: _date });
if (id) { if (!id) {
notify(t('orderUpdated'), 'positive'); const response = await api.post(
if (route.query.continue === 'catalog') { 'Orders',
router.push({ name: 'catalog' }); {
} else { sourceApp: 'WEB',
router.push({ name: 'basket', params: { id } }); landed: new Date(date),
} clientFk: userId,
companyFk: 442, // SELECT defaultCompanyFk FROM orderConfig; (wtf)
addressFk: orderForm.value.address,
agencyModeFk: orderForm.value.agency,
configured: new Date(),
},
);
const orderId = response.data.id;
appStore.loadIntoBasket(orderId);
router.push({ name: 'catalog' });
} else { } else {
const orderId = resultSet.results[1].data[0]['@orderId']; orderForm.value.id = id;
appStore.loadIntoBasket(orderId); let query = 'CALL myOrder_configure(#id, #date, #method, #agency, #address)';
let resultSet = await jApi.execQuery(query, { ...restOfForm, date: _date });
notify(t('orderUpdated'), 'positive');
if (route.query.continue === 'catalog') {
router.push({ name: 'catalog' }); router.push({ name: 'catalog' });
} else {
router.push({ name: 'basket', params: { id } });
}
} }
} catch (error) { } catch (error) {
console.error('Error submitting order:', error); console.error('Error submitting order:', error);