procurement-vuex
Version:
Commerce vuex module
42 lines (40 loc) • 1.25 kB
JavaScript
import humps from 'lodash-humps';
import purchaseOrderTemplateService from './purchase_order_template.service';
const { doFetchList } = purchaseOrderTemplateService
export default {
namespaced: true,
state: {
list: [],
inProgress: false,
},
mutations: {
inProgress(state, yesOrNo) {
state.inProgress = yesOrNo
},
setList(state, list) {
state.list = list;
},
},
actions: {
fetchList: async ({ commit}, { appId, purchaserBusinessEntityId, status }) => {
commit('inProgress', true);
try {
let templatesList = await doFetchList({ appId, purchaserBusinessEntityId, status});
if(templatesList){
commit('setList', humps(templatesList))
commit('inProgress', false)
return ({ list: humps(templatesList) })
}else{
commit('setList', [])
commit('inProgress', false)
return []
}
} catch (err) {
throw 'error'
}
finally {
commit('inProgress', false);
}
},
}
}