refactor(ticket): usar nuevo api en lugar de japi en TicketView
gitea/hedera-web/pipeline/pr-beta This commit looks good
Details
gitea/hedera-web/pipeline/pr-beta This commit looks good
Details
This commit is contained in:
parent
aa66c086f2
commit
65b715078e
|
@ -2,6 +2,7 @@
|
|||
import { onMounted, inject, ref } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { formatDate } from 'src/lib/filters.js';
|
||||
|
||||
import TicketDetails from 'src/pages/Ecomerce/TicketDetails.vue';
|
||||
|
||||
|
@ -10,7 +11,7 @@ import { storeToRefs } from 'pinia';
|
|||
import { usePrintService } from 'src/composables/usePrintService';
|
||||
|
||||
const { t } = useI18n();
|
||||
const jApi = inject('jApi');
|
||||
const api = inject('api');
|
||||
const route = useRoute();
|
||||
const appStore = useAppStore();
|
||||
const { isHeaderMounted } = storeToRefs(appStore);
|
||||
|
@ -20,21 +21,83 @@ const ticket = ref({});
|
|||
const rows = ref([]);
|
||||
const services = ref(null);
|
||||
const packages = ref(null);
|
||||
const dateFormat = 'DD/MM/YYYY';
|
||||
|
||||
const fetchTicketData = async ticketId => {
|
||||
const { data } = await api.post('applications/myTicket_get/execute-proc', {
|
||||
schema: 'hedera',
|
||||
params: [ticketId]
|
||||
});
|
||||
return data?.[0] || null;
|
||||
};
|
||||
|
||||
const fetchTicketRows = async ticketId => {
|
||||
const { data } = await api.post(
|
||||
'applications/myTicket_getRows/execute-proc',
|
||||
{
|
||||
schema: 'hedera',
|
||||
params: [ticketId]
|
||||
}
|
||||
);
|
||||
return data || [];
|
||||
};
|
||||
|
||||
const fetchTicketServices = async ticketId => {
|
||||
const { data } = await api.post(
|
||||
'applications/myTicket_getServices/execute-proc',
|
||||
{
|
||||
schema: 'hedera',
|
||||
params: [ticketId]
|
||||
}
|
||||
);
|
||||
return data || null;
|
||||
};
|
||||
|
||||
const fetchTicketPackages = async ticketId => {
|
||||
const { data } = await api.post(
|
||||
'applications/myTicket_getPackages/execute-proc',
|
||||
{
|
||||
schema: 'hedera',
|
||||
params: [ticketId]
|
||||
}
|
||||
);
|
||||
return data || null;
|
||||
};
|
||||
|
||||
const formatTicketDates = ticketData => {
|
||||
if (!ticketData) return;
|
||||
|
||||
const dateFields = ['landed', 'shipped'];
|
||||
dateFields.forEach(field => {
|
||||
if (ticketData[field]) {
|
||||
ticketData[field] = formatDate(ticketData[field], dateFormat);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
const params = {
|
||||
ticket: parseInt(route.params.id)
|
||||
};
|
||||
ticket.value = await jApi.getObject('CALL myTicket_get(#ticket)', params);
|
||||
rows.value = await jApi.query('CALL myTicket_getRows(#ticket)', params);
|
||||
services.value = await jApi.query(
|
||||
'CALL myTicket_getServices(#ticket)',
|
||||
params
|
||||
);
|
||||
packages.value = await jApi.query(
|
||||
'CALL myTicket_getPackages(#ticket)',
|
||||
params
|
||||
);
|
||||
const ticketId = parseInt(route.params.id);
|
||||
|
||||
try {
|
||||
const [ticketData, rowsData, servicesData, packagesData] =
|
||||
await Promise.all([
|
||||
fetchTicketData(ticketId),
|
||||
fetchTicketRows(ticketId),
|
||||
fetchTicketServices(ticketId),
|
||||
fetchTicketPackages(ticketId)
|
||||
]);
|
||||
|
||||
if (ticketData) {
|
||||
formatTicketDates(ticketData);
|
||||
ticket.value = ticketData;
|
||||
}
|
||||
|
||||
rows.value = rowsData;
|
||||
services.value = servicesData;
|
||||
packages.value = packagesData;
|
||||
} catch (error) {
|
||||
console.error('Error fetching ticket data:', error);
|
||||
}
|
||||
});
|
||||
|
||||
const onPrintClick = () =>
|
||||
|
|
Loading…
Reference in New Issue