75 lines
1.6 KiB
JavaScript
75 lines
1.6 KiB
JavaScript
import { fetchWrapper } from "@/shared/fetchWrapper";
|
||
|
||
const state = () => ({
|
||
firstName: "",
|
||
lastName: "",
|
||
patronymic: "",
|
||
birthDate: "",
|
||
gender: "",
|
||
marks: [],
|
||
addresses: [
|
||
{
|
||
category: "fact",
|
||
full_address: "г.Рязань, ул. Новикова-Прибоя, д.43/1, кв.2",
|
||
},
|
||
{
|
||
category: "registration",
|
||
full_address: "г.Санкт-Себастьянг, ул. Шоссе Энтузиастов, д.243, кв.4",
|
||
},
|
||
],
|
||
contacts: [
|
||
{ category: "email", value: "dol@yandex.ru" },
|
||
{ category: "phone", value: "+79586541252" },
|
||
],
|
||
});
|
||
|
||
const getters = {
|
||
PERSON(state) {
|
||
return {
|
||
firstName: state.firstName,
|
||
lastName: state.lastName,
|
||
patronymic: state.patronymic,
|
||
birthDate: state.birthDate,
|
||
gender: state.gender,
|
||
marks: ["hard", "rich", "allergic", "infected", "ban"],
|
||
};
|
||
},
|
||
ADDRESSES(state) {
|
||
return state.addresses;
|
||
},
|
||
CONTACTS(state) {
|
||
return state.contacts;
|
||
},
|
||
};
|
||
|
||
const actions = {
|
||
GET_PERSON({ commit }, id) {
|
||
fetchWrapper
|
||
.get(`persons/${id}`)
|
||
.then((res) => {
|
||
commit("SET_PERSON", res);
|
||
})
|
||
.catch((e) => alert(e));
|
||
},
|
||
UPDATE_PERSON(context, { obj, id }) {
|
||
fetchWrapper.patch(`persons/${id}`, obj);
|
||
},
|
||
};
|
||
|
||
const mutations = {
|
||
SET_PERSON(state, payload) {
|
||
state.firstName = payload.first_name;
|
||
state.lastName = payload.last_name;
|
||
state.patronymic = payload.patronymic;
|
||
state.birthDate = payload.birth_date;
|
||
state.gender = payload.gender;
|
||
},
|
||
};
|
||
|
||
export default {
|
||
state,
|
||
getters,
|
||
actions,
|
||
mutations,
|
||
};
|