Added optimization to reduce unnecessary requests

This commit is contained in:
irtiza-h30
2021-08-23 14:23:14 -04:00
parent 0330eb7f39
commit dc049dedf7

View File

@@ -264,80 +264,91 @@ export class API extends RESTDataSource {
if (profile.profileType === 'ssid') { if (profile.profileType === 'ssid') {
const { const {
id, id,
details: { passpointProfileId, passpointConfig }, details: { passpointProfileId = {}, passpointConfig },
} = profile; } = profile;
const oldProfile = await this.get('portal/profile', { profileId: id }); const oldProfile = await this.get('portal/profile', { profileId: id });
if (oldProfile.childProfileIds.length) { if (oldProfile.childProfileIds.length) {
const childProfiles = await this.get('portal/profile/inSet', { const childProfiles =
profileIdSet: oldProfile.childProfileIds, (await this.get('portal/profile/inSet', {
}); profileIdSet: oldProfile.childProfileIds,
})) || [];
const passpointProfile = childProfiles.find( const passpointProfile = childProfiles.find(
(profile) => profile.profileType === 'passpoint' (profile) => profile.profileType === 'passpoint'
); );
console.log(passpointProfileId.value);
if (passpointProfile) { if (passpointProfile) {
this.put('portal/profile', { if (
...passpointProfile, !passpointProfileId.value ||
details: { passpointProfile.id !== parseInt(passpointProfileId.value, 10)
...passpointProfile.details, ) {
...(passpointProfile.details.osuSsidProfileId === parseInt(id, 10) && { this.put('portal/profile', {
osuSsidProfileId: null, ...passpointProfile,
}), details: {
...(passpointProfile.details.associatedAccessSsidProfileIds && { ...passpointProfile.details,
associatedAccessSsidProfileIds: passpointProfile.details.associatedAccessSsidProfileIds.filter( ...(passpointProfile.details.osuSsidProfileId === parseInt(id, 10) && {
(i) => i !== parseInt(id, 10) osuSsidProfileId: null,
), }),
}), ...(passpointProfile.details.associatedAccessSsidProfileIds && {
}, associatedAccessSsidProfileIds: passpointProfile.details.associatedAccessSsidProfileIds.filter(
}); (i) => i !== parseInt(id, 10)
),
}),
},
});
}
} }
} }
if (passpointConfig === 'accessSSID') { if (passpointProfileId.value) {
this.get('portal/profile', { if (passpointConfig === 'accessSSID') {
profileId: passpointProfileId.value, this.get('portal/profile', {
}).then((profile) => { profileId: passpointProfileId.value,
this.put('portal/profile', { }).then((profile) => {
...profile, this.put('portal/profile', {
details: { ...profile,
...profile.details, details: {
...(profile.details.osuSsidProfileId === parseInt(id, 10) && { ...profile.details,
osuSsidProfileId: null, ...(profile.details.osuSsidProfileId === parseInt(id, 10) && {
}), osuSsidProfileId: null,
associatedAccessSsidProfileIds: profile.details.associatedAccessSsidProfileIds }),
? [...profile.details.associatedAccessSsidProfileIds, id] associatedAccessSsidProfileIds: profile.details.associatedAccessSsidProfileIds
: [id], ? [...profile.details.associatedAccessSsidProfileIds, id]
}, : [id],
}); },
});
} else if (passpointConfig === 'osuSSID') {
this.get('portal/profile', {
profileId: passpointProfileId.value,
}).then((profile) => {
if (profile.details.osuSsidProfileId) {
this.get('portal/profile', {
profileId: profile.details.osuSsidProfileId,
}).then((ssidProfile) => {
this.put('portal/profile', {
...ssidProfile,
childProfileIds: ssidProfile.childProfileIds.filter((i) => i !== profile.id),
});
}); });
}
this.put('portal/profile', {
...profile,
details: {
...profile.details,
...(profile.details.associatedAccessSsidProfileIds && {
associatedAccessSsidProfileIds: profile.details.associatedAccessSsidProfileIds.filter(
(i) => i !== parseInt(id, 10)
),
}),
osuSsidProfileId: id,
},
}); });
}); } else if (passpointConfig === 'osuSSID') {
this.get('portal/profile', {
profileId: passpointProfileId.value,
}).then((profile) => {
if (profile.details.osuSsidProfileId) {
this.get('portal/profile', {
profileId: profile.details.osuSsidProfileId,
}).then((ssidProfile) => {
this.put('portal/profile', {
...ssidProfile,
childProfileIds: ssidProfile.childProfileIds.filter((i) => i !== profile.id),
});
});
}
this.put('portal/profile', {
...profile,
details: {
...profile.details,
...(profile.details.associatedAccessSsidProfileIds && {
associatedAccessSsidProfileIds: profile.details.associatedAccessSsidProfileIds.filter(
(i) => i !== parseInt(id, 10)
),
}),
osuSsidProfileId: id,
},
});
});
}
} }
} }
@@ -352,9 +363,11 @@ export class API extends RESTDataSource {
if (deletedProfile.profileType === 'ssid') { if (deletedProfile.profileType === 'ssid') {
if (deletedProfile.childProfileIds.length) { if (deletedProfile.childProfileIds.length) {
const childProfiles = await this.get('portal/profile/inSet', { const childProfiles =
profileIdSet: deletedProfile.childProfileIds, (await this.get('portal/profile/inSet', {
}); profileIdSet: deletedProfile.childProfileIds,
})) || [];
const passpointProfile = childProfiles.find( const passpointProfile = childProfiles.find(
(profile) => profile.profileType === 'passpoint' (profile) => profile.profileType === 'passpoint'
); );