UNPKG

commerce-vuex

Version:
255 lines (245 loc) 8.87 kB
import humps from "lodash-humps"; import businessEntityService from "./business_entity.service"; const { doFetchList, doFetchForPortfolioSelection, doBusinessEntityLookupList, doFetchBusinessEntityListByIds, doFetchBusinessEntityListByOwnerId, doFetchBusinessOwnerList } = businessEntityService; export default { namespaced: true, state: { list: [], businessEntityLookupList: [], selected: [], recordsCount: 0, inProgress: false, fetchInProgress:false, error: null, businessOwnerList:[], businessOwnerListInProgress:false, vendorBusinessEntityLookupList:[] }, mutations: { inProgress(state, yesOrNo) { state.inProgress = yesOrNo; }, fetchInProgress(state, yesOrNo) { state.fetchInProgress = yesOrNo; }, businessOwnerListInProgress(state, yesOrNo) { state.businessOwnerListInProgress = yesOrNo; }, setList(state, list) { state.selected = []; for (let i in state.list) { state.selected.push(false); state.selected[i] = false; } state.list = list; }, setBusinessEntityLookupList(state, list) { let serviceList=[] for(let i=0; i <list.length;i++){ let resp =list[i] for (let j=0;j<resp.services.length;j++){ if(resp.services[j]) resp.services[j].vendor= resp ?resp: null serviceList.push(resp.services[j]) } } state.vendorBusinessEntityLookupList = serviceList state.businessEntityLookupList = list; }, setListCount(state, number) { state.recordsCount = number; }, setBusinessOwnerList(state, list) { state.businessOwnerList = list; }, }, actions: { fetchList: async ( { commit }, { appId, nameLike, activeProfiles, businessEntityId, pageNumber, limit,platformStatus } ) => { commit("inProgress", true); try { let offset = (pageNumber - 1) * limit; const response = await doFetchList({ appId, nameLike, activeProfiles, businessEntityId, limit, offset, platformStatus }); if (response.range != null) { let recordsCount = response.range.split("/"); commit("setListCount", Number(recordsCount[1])); const list = await response.data; if (list) { commit("setList", humps(list)); commit("inProgress", false); return humps(list); } else { commit("setList", []); commit("inProgress", false); return []; } /*if (recursive && state.list[0].appId != rootState.appOne.one.id) { dispatch('appOne/fetchOne', state.list[0].appId, { root: true }); }*/ } } catch (err) { // eslint-disable-next-line no-useless-catch throw err; } finally { commit("inProgress", false); } }, fetchForPortfolioSelection: async ( { commit }, { appId, pageNumber, limit } ) => { commit("inProgress", true); try { let offset = (pageNumber - 1) * limit; const response = await doFetchForPortfolioSelection({ appId, limit, offset, }); if (response.range != null) { const list = await response.data; if (list) { commit("inProgress", false); return humps(list); } else { commit("inProgress", false); return []; } /*if (recursive && state.list[0].appId != rootState.appOne.one.id) { dispatch('appOne/fetchOne', state.list[0].appId, { root: true }); }*/ } } catch (err) { // eslint-disable-next-line no-useless-catch throw err; } finally { commit("inProgress", false); } }, businessEntityLookupList: async ({ commit }, { appId, filter }) => { commit("fetchInProgress", true); try { const response = await doBusinessEntityLookupList({ appId, filter }); if (response) { commit('setBusinessEntityLookupList', humps(response)); commit('setListCount', Number(response? response.length : 0)); commit('fetchInProgress', false) return { error: false, list: humps((response)) } } else { commit('setBusinessEntityLookupList', []); commit('fetchInProgress', false) return ({ error: false, list: [] }) } } // eslint-disable-next-line no-useless-catch catch (err) { console.log(err) // throw err return { error: true, err } } finally { commit("inProgress", false); } }, fetchBusinessEntityListByIds: async ( { commit }, { appId, businessEntityIds } ) => { commit("inProgress", true); try { const list = await doFetchBusinessEntityListByIds({ appId, businessEntityIds, }); if (list) { commit("setList", humps(list)); return list; } else { commit("setList", []); } } catch (err) { // eslint-disable-next-line no-useless-catch throw err; } finally { commit("inProgress", false); } }, fetchListByOwnerId: async ( { commit }, { appId, ownerId, activeProfiles, nameLike, pageNumber, limit } ) => { commit("inProgress", true); try { let offset = (pageNumber - 1) * limit; const response = await doFetchBusinessEntityListByOwnerId({ appId, ownerId, nameLike, activeProfiles, offset, limit, }); if (response.range != null) { let recordsCount = response.range.split("/"); commit("setListCount", Number(recordsCount[1])); const list = await response.data; if (list) { commit("setList", humps(list)); commit("inProgress", false); return humps(list); } else { commit("setList", []); commit("inProgress", false); return []; } } } catch (err) { // eslint-disable-next-line no-useless-catch throw err; } finally { commit("inProgress", false); } }, fetchBusinessOwnerList: async ( { commit }, { appId, nameLike } ) => { commit("businessOwnerListInProgress", true); try { const list = await doFetchBusinessOwnerList({ appId, nameLike, }); if (list) { commit("setBusinessOwnerList", humps(list)); return list; } else { commit("setBusinessOwnerList", []); } commit("businessOwnerListInProgress", false); } catch (err) { // eslint-disable-next-line no-useless-catch throw err; } finally { commit("businessOwnerListInProgress", false); } }, }, };