refactor: refs #6900 create setRectificative composable
gitea/salix-front/pipeline/pr-master This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-09-04 10:30:14 +02:00
parent 00beeaf51b
commit 763cf2e345
3 changed files with 18 additions and 29 deletions

View File

@ -3,8 +3,8 @@ import VnCard from 'components/common/VnCard.vue';
import InvoiceInDescriptor from './InvoiceInDescriptor.vue'; import InvoiceInDescriptor from './InvoiceInDescriptor.vue';
import InvoiceInFilter from '../InvoiceInFilter.vue'; import InvoiceInFilter from '../InvoiceInFilter.vue';
import InvoiceInSearchbar from '../InvoiceInSearchbar.vue'; import InvoiceInSearchbar from '../InvoiceInSearchbar.vue';
import axios from 'axios';
import { onBeforeRouteUpdate } from 'vue-router'; import { onBeforeRouteUpdate } from 'vue-router';
import { setRectificative } from '../composables/setRectificative';
const filter = { const filter = {
include: [ include: [
@ -23,19 +23,7 @@ const filter = {
], ],
}; };
onBeforeRouteUpdate(async (to) => { onBeforeRouteUpdate(async (to) => await setRectificative(to));
const card = to.matched.find((route) => route.name === 'InvoiceInCard');
const corrective = card.children.find(
(route) => route.name === 'InvoiceInCorrective'
);
const isRectificative = !!(
await axios.get('InvoiceInCorrections', {
params: { filter: { where: { correctingFk: to.params.id } } },
})
).data.length;
corrective.meta.hidden = !isRectificative;
});
</script> </script>
<template> <template>
<VnCard <VnCard

View File

@ -0,0 +1,14 @@
import axios from 'axios';
export async function setRectificative(route) {
const card = route.matched.find((route) => route.name === 'InvoiceInCard');
const corrective = card.children.find(
(route) => route.name === 'InvoiceInCorrective'
);
corrective.meta.hidden = !(
await axios.get('InvoiceInCorrections', {
params: { filter: { where: { correctingFk: route.params.id } } },
})
).data.length;
}

View File

@ -1,6 +1,5 @@
import { RouterView } from 'vue-router'; import { RouterView } from 'vue-router';
import axios from 'axios'; import { setRectificative } from 'src/pages/InvoiceIn/composables/setRectificative';
export default { export default {
path: '/invoice-in', path: '/invoice-in',
name: 'InvoiceIn', name: 'InvoiceIn',
@ -65,19 +64,7 @@ export default {
component: () => import('src/pages/InvoiceIn/Card/InvoiceInCard.vue'), component: () => import('src/pages/InvoiceIn/Card/InvoiceInCard.vue'),
redirect: { name: 'InvoiceInSummary' }, redirect: { name: 'InvoiceInSummary' },
beforeEnter: async (to, from, next) => { beforeEnter: async (to, from, next) => {
const isRectificative = !!( await setRectificative(to);
await axios.get('InvoiceInCorrections', {
params: { filter: { where: { correctingFk: to.params.id } } },
})
).data.length;
const card = to.matched.find((route) => route.name === 'InvoiceInCard');
const corrective = card.children.find(
(route) => route.name === 'InvoiceInCorrective'
);
corrective.meta.hidden = !isRectificative;
next(); next();
}, },
children: [ children: [