2020-05-30 11:58:00 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
|
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) {
|
2020-05-30 11:58:00 +00:00
|
|
|
Vue.set(state.records, index, data);
|
2019-12-21 17:24:35 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-06-22 07:49:26 +00:00
|
|
|
/* when you don't want to overwrite the whole object */
|
|
|
|
export const updateAttributes = (state, data) => {
|
|
|
|
state.records.forEach((element, index) => {
|
|
|
|
if (element.id === data.id) {
|
|
|
|
Vue.set(state.records, index, { ...state.records[index], ...data });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-07-04 06:12:47 +00:00
|
|
|
export const updatePresence = (state, data) => {
|
|
|
|
state.records.forEach((element, index) => {
|
|
|
|
const availabilityStatus = data[element.id];
|
2022-04-25 14:34:41 +00:00
|
|
|
Vue.set(
|
|
|
|
state.records[index],
|
|
|
|
'availability_status',
|
|
|
|
availabilityStatus || 'offline'
|
|
|
|
);
|
2020-07-04 06:12:47 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-12-21 17:24:35 +00:00
|
|
|
export const destroy = (state, id) => {
|
|
|
|
state.records = state.records.filter(record => record.id !== id);
|
|
|
|
};
|