1import api from '@/store/api'; 2import i18n from '@/i18n'; 3 4const MemoryStore = { 5 namespaced: true, 6 state: { 7 dimms: [], 8 }, 9 getters: { 10 dimms: (state) => state.dimms, 11 }, 12 mutations: { 13 setMemoryInfo: (state, data) => { 14 state.dimms = data.map(({ data }) => { 15 const { 16 Id, 17 Status = {}, 18 PartNumber, 19 SerialNumber, 20 SparePartNumber, 21 Description, 22 MemoryType, 23 MemorySize, 24 LocationIndicatorActive, 25 Location, 26 } = data; 27 return { 28 id: Id, 29 health: Status.Health, 30 partNumber: PartNumber, 31 serialNumber: SerialNumber, 32 statusState: Status.State, 33 sparePartNumber: SparePartNumber, 34 description: Description, 35 memoryType: MemoryType, 36 memorySize: MemorySize, 37 identifyLed: LocationIndicatorActive, 38 uri: data['@odata.id'], 39 locationNumber: Location?.PartLocation?.ServiceLabel, 40 }; 41 }); 42 }, 43 }, 44 actions: { 45 async getDimms({ commit }) { 46 return await api 47 .get('/redfish/v1/Systems/system/Memory') 48 .then(({ data: { Members } }) => { 49 const promises = Members.map((item) => api.get(item['@odata.id'])); 50 return api.all(promises); 51 }) 52 .then((response) => commit('setMemoryInfo', response)) 53 .catch((error) => console.log(error)); 54 }, 55 async updateIdentifyLedValue({ dispatch }, led) { 56 const uri = led.uri; 57 const updatedIdentifyLedValue = { 58 LocationIndicatorActive: led.identifyLed, 59 }; 60 return await api.patch(uri, updatedIdentifyLedValue).catch((error) => { 61 dispatch('getDimms'); 62 console.log('error', error); 63 if (led.identifyLed) { 64 throw new Error(i18n.t('pageInventory.toast.errorEnableIdentifyLed')); 65 } else { 66 throw new Error( 67 i18n.t('pageInventory.toast.errorDisableIdentifyLed') 68 ); 69 } 70 }); 71 }, 72 }, 73}; 74 75export default MemoryStore; 76