1import api from '@/store/api';
2
3const PostCodeLogsStore = {
4  namespaced: true,
5  state: {
6    allPostCodes: [],
7  },
8  getters: {
9    allPostCodes: (state) => state.allPostCodes,
10  },
11  mutations: {
12    setAllPostCodes: (state, allPostCodes) =>
13      (state.allPostCodes = allPostCodes),
14  },
15  actions: {
16    async getPostCodesLogData({ commit }) {
17      return await api
18        .get('/redfish/v1/Systems/system/LogServices/PostCodes/Entries')
19        .then(({ data: { Members = [] } = {} }) => {
20          const postCodeLogs = Members.map((log) => {
21            const { Created, MessageArgs, AdditionalDataURI } = log;
22            return {
23              date: new Date(Created),
24              bootCount: MessageArgs[0],
25              timeStampOffset: MessageArgs[1],
26              postCode: MessageArgs[2],
27              uri: AdditionalDataURI,
28            };
29          });
30          commit('setAllPostCodes', postCodeLogs);
31        })
32        .catch((error) => {
33          console.log('POST Codes Log Data:', error);
34        });
35    },
36  },
37};
38
39export default PostCodeLogsStore;
40