From 83d56e5d32d6e96d804338ee431fd92ac391f42f Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 10 Jun 2024 09:28:38 +0200 Subject: [PATCH] refactor: refs #5447 changed warehouse out filter behavior --- src/pages/Travel/ExtraCommunityFilter.vue | 49 ++++++++--------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/src/pages/Travel/ExtraCommunityFilter.vue b/src/pages/Travel/ExtraCommunityFilter.vue index c96ea19c2..095d8cbfb 100644 --- a/src/pages/Travel/ExtraCommunityFilter.vue +++ b/src/pages/Travel/ExtraCommunityFilter.vue @@ -21,6 +21,7 @@ const warehousesOptions = ref([]); const continentsOptions = ref([]); const agenciesOptions = ref([]); const suppliersOptions = ref([]); +const warehousesByContinent = ref({}); const add = (paramsObj, key) => { if (paramsObj[key] === undefined) { @@ -36,28 +37,25 @@ const decrement = (paramsObj, key) => { paramsObj[key]--; }; -const warehousesAm = ref([]); const warehouses = async () => { - const warehouses = await axios.get('Warehouses'); - const countries = await axios.get('Countries'); - const continents = await axios.get('Continents', { - params: { - filter: { where: { code: 'AM' } }, - }, - }); + const warehousesResponse = await axios.get('Warehouses'); + const countriesResponse = await axios.get('Countries'); + const continentsResponse = await axios.get('Continents'); - const countryContinent = countries.data.reduce((acc, c) => { - acc[c.id] = c.continentFk; + const countryContinentMap = countriesResponse.data.reduce((acc, country) => { + acc[country.id] = country.continentFk; return acc; }, {}); - const countriesInAM = Object.keys(countryContinent).filter( - (countryId) => countryContinent[countryId] === continents.data[0].id.toString() - ); + continentsResponse.data.forEach((continent) => { + const countriesInContinent = Object.keys(countryContinentMap).filter( + (countryId) => countryContinentMap[countryId] === continent.id.toString() + ); - warehousesAm.value = warehouses.data.filter((w) => - countriesInAM.includes(w.countryFk.toString()) - ); + warehousesByContinent.value[continent.code] = warehousesResponse.data.filter( + (warehouse) => countriesInContinent.includes(warehouse.countryFk.toString()) + ); + }); }; warehouses(); @@ -173,27 +171,13 @@ warehouses(); /> - + -