2019-12-21 17:24:35 +00:00
|
|
|
export const set = (state, data) => {
|
|
|
|
state.records = data;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const create = (state, data) => {
|
|
|
|
state.records.push(data);
|
|
|
|
};
|
|
|
|
|
2019-12-28 16:26:42 +00:00
|
|
|
export const setSingleRecord = (state, data) => {
|
|
|
|
const recordIndex = state.records.findIndex(record => record.id === data.id);
|
|
|
|
if (recordIndex > -1) {
|
|
|
|
state.records[recordIndex] = data;
|
|
|
|
} else {
|
|
|
|
create(state, data);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-21 17:24:35 +00:00
|
|
|
export const update = (state, data) => {
|
|
|
|
state.records.forEach((element, index) => {
|
|
|
|
if (element.id === data.id) {
|
|
|
|
state.records[index] = data;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const destroy = (state, id) => {
|
|
|
|
state.records = state.records.filter(record => record.id !== id);
|
|
|
|
};
|