Sandeepa Singh | 06d5386 | 2021-05-24 13:51:09 +0530 | [diff] [blame] | 1 | import api from '@/store/api'; |
Konstantin Aladyshev | d8c71c0 | 2023-02-15 12:49:11 +0000 | [diff] [blame] | 2 | import i18n from '@/i18n'; |
Sandeepa Singh | 06d5386 | 2021-05-24 13:51:09 +0530 | [diff] [blame] | 3 | |
| 4 | const 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 Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 19 | .get( |
| 20 | `${await this.dispatch('global/getSystemPath')}/LogServices/PostCodes/Entries`, |
| 21 | ) |
Sandeepa Singh | 06d5386 | 2021-05-24 13:51:09 +0530 | [diff] [blame] | 22 | .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 Aladyshev | d8c71c0 | 2023-02-15 12:49:11 +0000 | [diff] [blame] | 39 | async deleteAllPostCodeLogs({ dispatch }, data) { |
| 40 | return await api |
| 41 | .post( |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 42 | `${await this.dispatch('global/getSystemPath')}/LogServices/PostCodes/Actions/LogService.ClearLog`, |
Konstantin Aladyshev | d8c71c0 | 2023-02-15 12:49:11 +0000 | [diff] [blame] | 43 | ) |
| 44 | .then(() => dispatch('getPostCodesLogData')) |
| 45 | .then(() => |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 46 | i18n.tc('pagePostCodeLogs.toast.successDelete', data.length), |
Konstantin Aladyshev | d8c71c0 | 2023-02-15 12:49:11 +0000 | [diff] [blame] | 47 | ) |
| 48 | .catch((error) => { |
| 49 | console.log(error); |
| 50 | throw new Error( |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 51 | i18n.tc('pagePostCodeLogs.toast.errorDelete', data.length), |
Konstantin Aladyshev | d8c71c0 | 2023-02-15 12:49:11 +0000 | [diff] [blame] | 52 | ); |
| 53 | }); |
| 54 | }, |
Sandeepa Singh | 06d5386 | 2021-05-24 13:51:09 +0530 | [diff] [blame] | 55 | }, |
| 56 | }; |
| 57 | |
| 58 | export default PostCodeLogsStore; |