summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--store/users.js64
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;
+ },
+};