Updated create/update profile datasource

This commit is contained in:
irtiza-h30
2021-08-18 13:57:36 -04:00
parent 48035230fd
commit 9facd52419

View File

@@ -208,29 +208,38 @@ export class API extends RESTDataSource {
...profile,
});
if (profile.profileType === 'passpoint') {
if (profile.profileType === 'ssid') {
const {
id,
details: { associatedAccessSsidProfileIds, osuSsidProfileId },
} = newProfile;
this.get('portal/profile', {
profileId: osuSsidProfileId,
}).then((profile) => {
this.put('portal/profile', {
...profile,
childProfileIds: [...profile.childProfileIds, id],
});
});
associatedAccessSsidProfileIds.forEach((profileId) => {
details: { passpointProfileId, passpointConfig },
} = profile;
if (passpointConfig === 'accessSSID') {
this.get('portal/profile', {
profileId,
profileId: passpointProfileId.value,
}).then((profile) => {
this.put('portal/profile', {
...profile,
childProfileIds: [...profile.childProfileIds, id],
details: {
...profile.details,
associatedAccessSsidProfileIds: profile.details.associatedAccessSsidProfileIds
? [...profile.details.associatedAccessSsidProfileIds, newProfile.id]
: [newProfile.id],
},
});
});
});
} else if (passpointConfig === 'osuSSID') {
this.get('portal/profile', {
profileId: passpointProfileId.value,
}).then((profile) => {
this.put('portal/profile', {
...profile,
details: {
...profile.details,
osuSsidProfileId: newProfile.id,
},
});
});
}
}
return newProfile;
@@ -241,33 +250,73 @@ export class API extends RESTDataSource {
});
}
async updateProfile(profile) {
if (profile.profileType === 'passpoint') {
if (profile.profileType === 'ssid') {
const {
id,
details: { associatedAccessSsidProfileIds, osuSsidProfileId },
details: { passpointProfileId, passpointConfig },
} = profile;
this.get('portal/profile', {
profileId: osuSsidProfileId,
}).then((profile) => {
if (!profile.childProfileIds.includes(parseInt(id, 10))) {
if (passpointConfig === 'accessSSID') {
this.get('portal/profile', {
profileId: passpointProfileId.value,
}).then((profile) => {
this.put('portal/profile', {
...profile,
childProfileIds: [...profile.childProfileIds, id],
details: {
...profile.details,
...(profile.details.osuSsidProfileId === parseInt(id, 10) && {
osuSsidProfileId: null,
}),
associatedAccessSsidProfileIds: profile.details.associatedAccessSsidProfileIds
? [...profile.details.associatedAccessSsidProfileIds, id]
: [id],
},
});
}
});
associatedAccessSsidProfileIds.forEach((profileId) => {
});
} else if (passpointConfig === 'osuSSID') {
this.get('portal/profile', {
profileId,
profileId: passpointProfileId.value,
}).then((profile) => {
if (!profile.childProfileIds.includes(parseInt(id, 10))) {
this.put('portal/profile', {
...profile,
details: {
...profile.details,
...(profile.details.associatedAccessSsidProfileIds && {
associatedAccessSsidProfileIds: profile.details.associatedAccessSsidProfileIds.filter(
(i) => i !== parseInt(id, 10)
),
}),
osuSsidProfileId: id,
},
});
});
} else {
const oldProfile = await this.get('portal/profile', { profileId: id });
if (oldProfile.childProfileIds.length) {
const childProfiles = await this.get('portal/profile/inSet', {
profileIdSet: oldProfile.childProfileIds,
});
const passpointProfile = childProfiles.find(
(profile) => profile.profileType === 'passpoint'
);
if (passpointProfile) {
this.put('portal/profile', {
...profile,
childProfileIds: [...profile.childProfileIds, id],
...passpointProfile,
details: {
...passpointProfile.details,
...(passpointProfile.details.osuSsidProfileId === parseInt(id, 10) && {
osuSsidProfileId: null,
}),
...(passpointProfile.details.associatedAccessSsidProfileIds && {
associatedAccessSsidProfileIds: passpointProfile.details.associatedAccessSsidProfileIds.filter(
(i) => i !== parseInt(id, 10)
),
}),
},
});
}
});
});
}
}
}
return this.put('portal/profile', {