forked from nathalie/pedi2
48 lines
1.1 KiB
JavaScript
Vendored
48 lines
1.1 KiB
JavaScript
Vendored
import axios from "axios";
|
|
|
|
const state = {
|
|
grupos_de_compra: [],
|
|
};
|
|
|
|
const mutations = {
|
|
setGruposDeCompra(state, { data }) {
|
|
state.grupos_de_compra = data;
|
|
},
|
|
setGrupoDeCompra(state, gdc) {
|
|
for (var i = 0; i < state.grupos_de_compra.length; i++) {
|
|
if (state.grupos_de_compra[i].id == gdc.id) {
|
|
state.grupos_de_compra[i] = gdc;
|
|
return;
|
|
}
|
|
}
|
|
state.grupos_de_compra.push(gdc);
|
|
},
|
|
};
|
|
|
|
const actions = {
|
|
async getGruposDeCompra({ commit }) {
|
|
const response = await axios.get('/api/grupos-de-compra');
|
|
commit('setGruposDeCompra', response.data);
|
|
},
|
|
async setSaldo({ commit }, { gdc_id, saldo }) {
|
|
const response = await axios.post(
|
|
"api/grupos-de-compra/" + gdc_id + "/saldo",
|
|
{ saldo: saldo }
|
|
);
|
|
commit('setGrupoDeCompra', response.data.data);
|
|
},
|
|
};
|
|
|
|
const getters = {
|
|
getSaldo() {
|
|
return (gdc_id) => state.grupos_de_compra.find(gdc => gdc.id === gdc_id)?.saldo ?? 0;
|
|
},
|
|
};
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state,
|
|
mutations,
|
|
actions,
|
|
getters,
|
|
};
|