summaryrefslogtreecommitdiff
path: root/src/store/modules/AccessControl/LocalUserMangementStore.js
blob: 41bbe0d8a3928af74cf675c142a96d054a2ef63b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import api from "../../api";

const LocalUserManagementStore = {
  namespaced: true,
  state: {
    allUsers: []
  },
  getters: {
    allUsers(state) {
      return state.allUsers;
    }
  },
  mutations: {
    setUsers(state, allUsers) {
      state.allUsers = allUsers;
    }
  },
  actions: {
    getUsers({ commit }) {
      api
        .get("/redfish/v1/AccountService/Accounts")
        .then(response => {
          return response.data.Members.map(user => user["@odata.id"]);
        })
        .then(userIds => {
          return api.all(userIds.map(user => api.get(user)));
        })
        .then(users => {
          const userData = users.map(user => user.data);
          commit("setUsers", userData);
        })
        .catch(error => {
          console.log(error);
        });
    }
  }
};

export default LocalUserManagementStore;