blob: 9642ee42fb5cb7372e40507498eeb5a79c77c0be [file] [log] [blame]
Sandeepa Singh06d53862021-05-24 13:51:09 +05301import api from '@/store/api';
Konstantin Aladyshevd8c71c02023-02-15 12:49:11 +00002import i18n from '@/i18n';
Sandeepa Singh06d53862021-05-24 13:51:09 +05303
4const PostCodeLogsStore = {
5 namespaced: true,
6 state: {
7 allPostCodes: [],
8 },
9 getters: {
10 allPostCodes: (state) => state.allPostCodes,
11 },
12 mutations: {
13 setAllPostCodes: (state, allPostCodes) =>
14 (state.allPostCodes = allPostCodes),
15 },
16 actions: {
17 async getPostCodesLogData({ commit }) {
18 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +030019 .get(
20 `${await this.dispatch('global/getSystemPath')}/LogServices/PostCodes/Entries`,
21 )
Sandeepa Singh06d53862021-05-24 13:51:09 +053022 .then(({ data: { Members = [] } = {} }) => {
23 const postCodeLogs = Members.map((log) => {
24 const { Created, MessageArgs, AdditionalDataURI } = log;
25 return {
26 date: new Date(Created),
27 bootCount: MessageArgs[0],
28 timeStampOffset: MessageArgs[1],
29 postCode: MessageArgs[2],
30 uri: AdditionalDataURI,
31 };
32 });
33 commit('setAllPostCodes', postCodeLogs);
34 })
35 .catch((error) => {
36 console.log('POST Codes Log Data:', error);
37 });
38 },
Konstantin Aladyshevd8c71c02023-02-15 12:49:11 +000039 async deleteAllPostCodeLogs({ dispatch }, data) {
40 return await api
41 .post(
Sean Zhang8841b7d2024-06-15 08:42:41 +030042 `${await this.dispatch('global/getSystemPath')}/LogServices/PostCodes/Actions/LogService.ClearLog`,
Konstantin Aladyshevd8c71c02023-02-15 12:49:11 +000043 )
44 .then(() => dispatch('getPostCodesLogData'))
45 .then(() =>
Surya Vde23ea22024-07-11 15:19:46 +053046 i18n.global.t('pagePostCodeLogs.toast.successDelete', data.length),
Konstantin Aladyshevd8c71c02023-02-15 12:49:11 +000047 )
48 .catch((error) => {
49 console.log(error);
50 throw new Error(
Surya Vde23ea22024-07-11 15:19:46 +053051 i18n.global.t('pagePostCodeLogs.toast.errorDelete', data.length),
Konstantin Aladyshevd8c71c02023-02-15 12:49:11 +000052 );
53 });
54 },
Sandeepa Singh06d53862021-05-24 13:51:09 +053055 },
56};
57
58export default PostCodeLogsStore;