UNPKG

commerce-vuex

Version:
52 lines (49 loc) 1.47 kB
import humps from 'lodash-humps'; import stripeUserBillingHistory from './stripe_user_billing_history.service'; const { doFetchList } = stripeUserBillingHistory export default { namespaced: true, state: { list: [], selected: [], recordsCount: 0, inProgress: false, error: null }, mutations: { inProgress(state, yesOrNo) { state.inProgress = yesOrNo }, setList(state, list) { state.selected = []; for (let i in state.list) { state.selected.push(false); state.selected[i] = false; } state.list = list; }, setListCount(state, number) { state.recordsCount = number; } }, actions: { fetchList: async ({ commit }, { customerId, pageNumber, limit }) => { commit('inProgress', true); try { const response = await doFetchList({ customerId}); const list = await response.data; if (list) { commit('setList', humps((list))); } else commit('setList', []); } // eslint-disable-next-line no-useless-catch catch (err) { throw err } finally { commit('inProgress', false) } }, } }