blob: 56e5631d82bf4cb0af7da95bcde1d675da740fe3 [file] [log] [blame]
Sneha Patela02c6f92021-09-09 12:40:38 -05001import api from '@/store/api';
2import i18n from '@/i18n';
3
4const AssemblyStore = {
5 namespaced: true,
6 state: {
7 assemblies: null,
8 },
9 getters: {
10 assemblies: (state) => state.assemblies,
11 },
12 mutations: {
13 setAssemblyInfo: (state, data) => {
14 state.assemblies = data.map((assembly) => {
15 const {
16 MemberId,
17 PartNumber,
18 SerialNumber,
19 SparePartNumber,
20 Model,
21 Name,
22 Location,
23 LocationIndicatorActive,
24 } = assembly;
25 return {
26 id: MemberId,
27 partNumber: PartNumber,
28 serialNumber: SerialNumber,
29 sparePartNumber: SparePartNumber,
30 model: Model,
31 name: Name,
32 locationNumber: Location?.PartLocation?.ServiceLabel,
33 identifyLed: LocationIndicatorActive,
34 uri: assembly['@odata.id'],
35 };
36 });
37 },
38 },
39 actions: {
40 async getAssemblyInfo({ commit }) {
41 return await api
42 .get('/redfish/v1/Chassis/chassis/Assembly')
43 .then(({ data }) => commit('setAssemblyInfo', data?.Assemblies))
44 .catch((error) => console.log(error));
45 },
46 async updateIdentifyLedValue({ dispatch }, led) {
47 const uri = led.uri;
48 const updatedIdentifyLedValue = {
49 LocationIndicatorActive: led.identifyLed,
50 };
51 return await api.patch(uri, updatedIdentifyLedValue).catch((error) => {
52 dispatch('getAssemblyInfo');
53 console.log('error', error);
54 if (led.identifyLed) {
55 throw new Error(i18n.t('pageInventory.toast.errorEnableIdentifyLed'));
56 } else {
57 throw new Error(
58 i18n.t('pageInventory.toast.errorDisableIdentifyLed')
59 );
60 }
61 });
62 },
63 },
64};
65
66export default AssemblyStore;