perf: refs #8180 simplify ticket checking by combining hasTickets logic
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jon Elias 2025-05-07 17:24:14 +02:00
parent b68f4331b8
commit d3b6223473
1 changed files with 12 additions and 18 deletions

View File

@ -66,10 +66,7 @@ const excludeType = computed({
const arrayData = useArrayData('ZoneEvents'); const arrayData = useArrayData('ZoneEvents');
const exclusionGeoCreate = async () => { const exclusionGeoCreate = async () => {
if (await hasTickets(route.params.id, dated.value)) { if (await zoneHasTickets(route.params.id, dated.value)) return;
await handleHasTickets();
return;
}
const params = { const params = {
zoneFk: parseInt(route.params.id), zoneFk: parseInt(route.params.id),
@ -92,10 +89,7 @@ const exclusionCreate = async () => {
}; };
const zoneIds = props.zoneIds?.length ? props.zoneIds : [route.params.id]; const zoneIds = props.zoneIds?.length ? props.zoneIds : [route.params.id];
for (const id of zoneIds) { for (const id of zoneIds) {
if (await hasTickets(id, dated.value)) { if (await zoneHasTickets(id, dated.value)) return;
await handleHasTickets();
return;
}
const url = `Zones/${id}/exclusions`; const url = `Zones/${id}/exclusions`;
let today = moment(dated.value); let today = moment(dated.value);
@ -133,7 +127,7 @@ const exclusionCreate = async () => {
await refetchEvents(); await refetchEvents();
}; };
const hasTickets = async (zoneId, date) => { const zoneHasTickets = async (zoneId, date) => {
const filter = { const filter = {
where: { where: {
zoneFk: zoneId, zoneFk: zoneId,
@ -142,15 +136,15 @@ const hasTickets = async (zoneId, date) => {
}; };
const params = { filter: JSON.stringify(filter) }; const params = { filter: JSON.stringify(filter) };
const { data } = await axios.get('Tickets', { params }); const { data } = await axios.get('Tickets', { params });
return data.length > 0; if (data.length > 0) {
};
const handleHasTickets = async (zoneId, date) => {
quasar.notify({ quasar.notify({
message: t('eventsExclusionForm.cantCloseZone'), message: t('eventsExclusionForm.cantCloseZone'),
type: 'negative', type: 'negative',
}); });
await refetchEvents(); await refetchEvents();
return true;
}
return false;
}; };
const onSubmit = async () => { const onSubmit = async () => {