12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- /* eslint-disable no-restricted-syntax */
- /* eslint-disable guard-for-in */
- import axios from 'axios';
- import _ from 'lodash';
-
- export default {
- namespaced: true,
- state: {
- regions: [],
- detailedRegion: [],
- },
- mutations: {
- setRegions(state, regions) {
- state.regions = regions;
- },
- clearDetailed(state) {
- state.detailedRegion = [];
- },
- addDetailed(state, detailed) {
- state.detailedRegion.push(detailed);
- },
- },
- getters: {},
- actions: {
- getRegions({
- commit,
- dispatch,
- }) {
- commit('clearDetailed');
- axios.get(
- 'https://www.tradeunipoint.com/unibackend/seam/resource/rest/products/regions/list/ZA/',
- )
- .then((result) => {
- commit('setRegions', result.data);
- if (result.data) {
- for (const i in result.data) {
- const region = result.data[i];
- dispatch('getDetailedRegion', region);
- }
- }
- })
- .catch(console.error);
- },
- getDetailedRegion({
- commit,
- }, region) {
- if (region) {
- axios
- .get(`https://www.tradeunipoint.com/unibackend/seam/resource/rest/products/resorts/${
- region.regionCode}/`)
- .then(result => commit('addDetailed', {
- id: region.id,
- regionCode: region.regionCode,
- regionName: region.regionName,
- resorts: result.data,
- }))
- .catch(console.error);
- }
- },
- },
- };
|