diff options
author | Santo Cariotti <santo@dcariotti.me> | 2022-09-24 19:45:30 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2022-09-24 19:45:30 +0200 |
commit | 9365e5a78a0e5b35892897a101b00a616f0813ac (patch) | |
tree | 505f445a95ef112a7746a6cb2a326a1c2f701e82 | |
parent | 33962f0b9650b32d1ee313a06cefc9f81b910e4c (diff) |
Users store
-rw-r--r-- | store/users.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/store/users.js b/store/users.js new file mode 100644 index 0000000..cb9b4b4 --- /dev/null +++ b/store/users.js @@ -0,0 +1,64 @@ +export const state = () => ({ + users: [], +}); + +export const getters = { + users: (state) => { + return state.users; + }, +}; + +export const mutations = { + saveUsers: (state, value) => { + state.users = value; + }, +}; + +export const actions = { + // Search user by `id` + async findById({ commit }, id) { + commit("loadingStatus", true, { root: true }); + let res = { status: 0, data: null }; + let api = this.$config.api; + + await fetch(`${api}/v1/users/${id}`, { + headers: { + "Content-Type": "application/json", + }, + }) + .then(async (response) => { + res.status = response.status; + res.data = await response.json(); + }) + .catch((e) => { + res.status = e.status; + }); + + commit("loadingStatus", false, { root: true }); + + return res; + }, + // Search user models + async findModels({ commit }, id) { + commit("loadingStatus", true, { root: true }); + let res = { status: 0, data: null }; + let api = this.$config.api; + + await fetch(`${api}/v1/users/${id}/models`, { + headers: { + "Content-Type": "application/json", + }, + }) + .then(async (response) => { + res.status = response.status; + res.data = await response.json(); + }) + .catch((e) => { + res.status = e.status; + }); + + commit("loadingStatus", false, { root: true }); + + return res; + }, +}; |