UNPKG

commerce-vuex

Version:
374 lines (358 loc) 14.4 kB
import humps from 'lodash-humps'; import brandService from './brand.service'; const { doFetchList, doFetchListByOwner, doFetchForPortfolioSelection, doFetchBrandListByIds, doFetchBrandServicedLookup, doFetchBrandClusterLookupList, doFetchBrandWithServiceLookupList ,doFetchBrandQueryList,doFetchServiceWithBrandAndBusiness} = brandService export default { namespaced: true, state: { list: [], listByOwner: [], brandList:[], selected: [], brandServicedLookupList:[], brandWithServiceLookupList:[], recordsCount: 0, inProgress: false, fetchInProgress: false, error: null, brandClusterLookupList: [], brandQueryList:[], brandQueryDetails:[], brandQueryActualList:[], serviceWithBrandAndBusinessList:[] }, mutations: { inProgress(state, yesOrNo) { state.inProgress = yesOrNo }, fetchInProgress(state, yesOrNo) { state.fetchInProgress = yesOrNo }, setList(state, list) { state.selected = []; for (let i in state.list) { state.selected.push(false); state.selected[i] = false; } state.list = list; }, setListByOwner(state, list) { state.listByOwner = list; }, setbrandList(state, list) { state.brandList = list; }, setBrandServicedLookupList(state, list) { state.brandServicedLookupList = list; }, setListCount(state, number) { state.recordsCount = number; }, setBrandClusterLookupList(state, list){ state.brandClusterLookupList = list }, setBrandServiceLookupList(state, list){ state.brandWithServiceLookupList = list }, setbrandQueryList(state, list){ let newData=[]; if(list.results) { state.brandQueryActualList = list.results; list.results.filter((item) => { let services= item.services ? item.services['4243']:[]; let obj= { "id":item.id, "name":item.name, ...services } newData.push(obj) }) } state.brandQueryList = newData; }, setbrandQueryOne(state, one){ let newData=[]; if(one.results) { one.results.filter((item) => { let services= item.services ? item.services['4243']:[]; let obj= { "id":item.id, "name":item.name, ...services } newData.push(obj) }) } state.brandQueryDetails = newData; }, setServiceWithBrandAndBusinessList(state, list){ state.serviceWithBrandAndBusinessList = list } }, actions: { fetchList: async ({ commit }, { appId, brandId, nameLike, pageNumber, limit,ownerId,name }) => { commit('inProgress', true); try { let offset = (pageNumber - 1) * limit; const response = await doFetchList({ appId, brandId, nameLike, limit, offset,ownerId,name }); if (response.range != null) { let recordsCount = response.range.split("/"); commit('setListCount', Number(recordsCount[1])); const list = await response.data; if (list) { commit('inProgress', false) commit('setList', humps((list))); return humps(list) } else commit('inProgress', false) commit('setList', []); return [] /*if (recursive && state.list[0].appId != rootState.appOne.one.id) { dispatch('appOne/fetchOne', state.list[0].appId, { root: true }); }*/ } } // eslint-disable-next-line no-useless-catch catch (err) { throw err } finally { commit('inProgress', false) } }, fetchBrandListByIds: async ({ commit }, { appId, brandIds, nameLike, pageNumber, limit }) => { commit('inProgress', true); try { let offset = (pageNumber - 1) * limit; const response = await doFetchBrandListByIds({ appId, brandIds, nameLike, limit, offset }); 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))); return humps(list) } else commit('setList', []); } } // eslint-disable-next-line no-useless-catch catch (err) { throw err } finally { commit('inProgress', false) } }, fetchListByOwner: async ({ commit }, { ownerId, appId }) => { commit('fetchInProgress', true); try { const list = await doFetchListByOwner({ ownerId, appId }); if (list) { commit('setListByOwner', humps((list))); commit('fetchInProgress', false) return humps((list)) } else commit('setListByOwner', []); commit('fetchInProgress', false) return [] } // eslint-disable-next-line no-useless-catch catch (err) { throw err } finally { commit('fetchInProgress', false) } }, fetchForPortfolioSelectionBrand: async ({ commit }, { ownerId, appId }) => { commit('fetchInProgress', true); try { const list = await doFetchForPortfolioSelection({ ownerId, appId }); if (list) { commit('fetchInProgress', false) return humps((list)) } else commit('fetchInProgress', false) return [] } // eslint-disable-next-line no-useless-catch catch (err) { throw err } finally { commit('fetchInProgress', false) } }, fetchBrandServicedLookupList: async ({ commit }, {filter,appId}) => { commit('fetchInProgress', true); try { const list = await doFetchBrandServicedLookup({filter,appId}); if (list) { commit('setBrandServicedLookupList', humps((list))); commit('fetchInProgress', false) return humps((list)) } else commit('setBrandServicedLookupList', []); commit('fetchInProgress', false) return [] } // eslint-disable-next-line no-useless-catch catch (err) { throw err } finally { commit('fetchInProgress', false) } }, fetchBrandClusterLookupList: async ({ commit }, { filter, appId }) => { commit('fetchInProgress', true); try { const list = await doFetchBrandClusterLookupList({ filter, appId }); if (list) { commit('fetchInProgress', false) commit('setBrandClusterLookupList', humps((list))); return humps((list)) } else{ commit('setBrandClusterLookupList', []); commit('fetchInProgress', false) } return [] } // eslint-disable-next-line no-useless-catch catch (err) { throw err } finally { commit('fetchInProgress', false) } }, fetchBrandWithServiceLookupList: async ({ commit }, { filter, appId }) => { commit('fetchInProgress', true); try { const list = await doFetchBrandWithServiceLookupList({ filter, appId }); if (list) { commit('fetchInProgress', false) commit('setBrandServiceLookupList', humps((list))); return humps((list)) } else{ commit('setBrandServiceLookupList', []); commit('fetchInProgress', false) } return [] } // eslint-disable-next-line no-useless-catch catch (err) { throw err } finally { commit('fetchInProgress', false) } }, fetchBrandUsingQuery: async ({ commit }, { appId, specsFormat }) => { commit('inProgress', true); try { // let offset = (pageNumber - 1) * limit; const response = await doFetchBrandQueryList({ appId, specsFormat }); if (response) { commit('inProgress', false) commit('setbrandQueryList', humps((response))); return humps(response) } else commit('inProgress', false) commit('setbrandQueryList', []); return [] /*if (recursive && state.list[0].appId != rootState.appOne.one.id) { dispatch('appOne/fetchOne', state.list[0].appId, { root: true }); }*/ } // eslint-disable-next-line no-useless-catch catch (err) { throw err } finally { commit('inProgress', false) } }, fetchBrandUsingQueryOne: async ({ commit }, { appId, specsFormat }) => { commit('inProgress', true); try { // let offset = (pageNumber - 1) * limit; const response = await doFetchBrandQueryList({ appId, specsFormat }); if (response) { commit('inProgress', false) commit('setbrandQueryOne', humps((response))); return humps(response) } else commit('inProgress', false) commit('setbrandQueryOne', []); return [] /*if (recursive && state.list[0].appId != rootState.appOne.one.id) { dispatch('appOne/fetchOne', state.list[0].appId, { root: true }); }*/ } // eslint-disable-next-line no-useless-catch catch (err) { throw err } finally { commit('inProgress', false) } }, searchBrandUsingQuery: async ({ commit }, { appId, specsFormat }) => { commit('inProgress', true); try { // let offset = (pageNumber - 1) * limit; const response = await doFetchBrandQueryList({ appId, specsFormat }); if (response) { commit('inProgress', false) commit('setbrandList', humps((response))); return humps(response) } else commit('inProgress', false) commit('setbrandList', []); return [] /*if (recursive && state.list[0].appId != rootState.appOne.one.id) { dispatch('appOne/fetchOne', state.list[0].appId, { root: true }); }*/ } // eslint-disable-next-line no-useless-catch catch (err) { throw err } finally { commit('inProgress', false) } }, fetchServiceWithBrandAndBusiness: async ({ commit }, {filterByOwnerId, brandId, appId,pageNumber, limit }) => { commit('fetchInProgress', true); try { let offset = (pageNumber - 1) * limit; const response = await doFetchServiceWithBrandAndBusiness({ filterByOwnerId,brandId, appId,limit, offset }); if (response.range != null) { let recordsCount = response.range.split("/"); commit('setListCount', Number(recordsCount[1])); const list = await response.data; if (list) { commit('inProgress', false) commit('setServiceWithBrandAndBusinessList', humps((list))); return humps(list) } else commit('inProgress', false) commit('setServiceWithBrandAndBusinessList', []); return [] } } // eslint-disable-next-line no-useless-catch catch (err) { throw err } finally { commit('fetchInProgress', false) } }, } }