refactor: refs #8180 get data from front instead of back

This commit is contained in:
Jon Elias 2025-05-07 16:53:23 +02:00
parent 20aea5b7df
commit 9d500a0655
2 changed files with 23 additions and 39 deletions

View File

@ -66,7 +66,10 @@ const excludeType = computed({
const arrayData = useArrayData('ZoneEvents'); const arrayData = useArrayData('ZoneEvents');
const exclusionGeoCreate = async () => { const exclusionGeoCreate = async () => {
if (await hasTicketsForDay(route.params.id, dated.value)) return; if (await hasTickets(route.params.id, dated.value)) {
await handleHasTickets();
return;
}
const params = { const params = {
zoneFk: parseInt(route.params.id), zoneFk: parseInt(route.params.id),
@ -89,7 +92,10 @@ 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 hasTicketsForDay(id, dated.value)) return; if (await hasTickets(id, dated.value)) {
await handleHasTickets();
return;
}
const url = `Zones/${id}/exclusions`; const url = `Zones/${id}/exclusions`;
let today = moment(dated.value); let today = moment(dated.value);
@ -128,26 +134,23 @@ const exclusionCreate = async () => {
}; };
const hasTickets = async (zoneId, date) => { const hasTickets = async (zoneId, date) => {
let hasDayTickets = await axios.get('Zones/getZoneTickets', { const filter = {
params: { where: {
zoneFk: zoneId, zoneFk: zoneId,
date: date, shipped: date,
}, },
}); };
const params = { filter: JSON.stringify(filter) };
const { data } = await axios.get('Tickets', { params });
return data.length > 0;
};
if (hasDayTickets.data.length > 0) { const handleHasTickets = async (zoneId, date) => {
quasar.notify({ quasar.notify({
message: t('eventsExclusionForm.cantCloseZone'), message: t('eventsExclusionForm.cantCloseZone'),
type: 'negative', type: 'negative',
}); });
return true; await refetchEvents();
}
return false;
};
const hasTicketsForDay = async (zoneId, date) => {
const tickets = await hasTickets(zoneId, date);
return tickets;
}; };
const onSubmit = async () => { const onSubmit = async () => {

View File

@ -26,27 +26,8 @@ describe('ZoneDeliveryDays', () => {
}); });
}).as('events'); }).as('events');
cy.dataCy('ZoneDeliveryDaysPostcodeSelect').type(postcode); cy.selectOption('[data-cy="ZoneDeliveryDaysPostcodeSelect"]', postcode);
cy.get('.q-menu .q-item').contains(postcode).click(); cy.selectOption('[data-cy="ZoneDeliveryDaysAgencySelect"]', agency);
cy.get('.q-menu').then(($menu) => {
if ($menu.is(':visible')) {
cy.get('[data-cy="ZoneDeliveryDaysPostcodeSelect"]')
.as('focusedElement')
.focus();
cy.get('@focusedElement').blur();
}
});
cy.dataCy('ZoneDeliveryDaysAgencySelect').type(agency);
cy.get('.q-menu .q-item').contains(agency).click();
cy.get('.q-menu').then(($menu) => {
if ($menu.is(':visible')) {
cy.get('[data-cy="ZoneDeliveryDaysAgencySelect"]')
.as('focusedElement')
.focus();
cy.get('@focusedElement').blur();
}
});
cy.get(submitForm).click(); cy.get(submitForm).click();
cy.wait('@events').then((interception) => { cy.wait('@events').then((interception) => {