Skip to content

Commit 0590de4

Browse files
committed
fixes for async get and patch methods
1 parent 718eab9 commit 0590de4

File tree

1 file changed

+52
-47
lines changed

1 file changed

+52
-47
lines changed

src/app/mydata/services/profile.service.ts

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -103,50 +103,53 @@ export class ProfileService {
103103
}
104104

105105
async checkProfileExists() {
106-
await this.updateToken().then(() => {
107-
return this.http.get(this.apiUrl + '/userprofile/', this.httpOptions);
108-
});
106+
await this.updateToken();
107+
let checkResult = await firstValueFrom(this.http.get(this.apiUrl + '/userprofile/', this.httpOptions));
108+
return checkResult;
109109
}
110110

111111
async createProfile() {
112-
await this.updateToken().then(() => {
113-
return this.http.post(
114-
this.apiUrl + '/userprofile/',
115-
null,
116-
this.httpOptions
117-
);
118-
});
112+
await this.updateToken();
113+
let createResponse = await firstValueFrom(
114+
this.http.post(
115+
this.apiUrl + '/userprofile/',
116+
null,
117+
this.httpOptions
118+
));
119+
return createResponse;
119120
}
120121

121122
async deleteProfile() {
122-
await this.updateToken().then(() => {
123-
return this.http.delete(this.apiUrl + '/userprofile/', this.httpOptions);
124-
});
123+
await this.updateToken();
124+
let deleteResponse = await firstValueFrom(
125+
this.http.delete(this.apiUrl + '/userprofile/', this.httpOptions)
126+
);
127+
return deleteResponse;
125128
}
126129

127-
async hideProfile() {
128-
await this.updateToken().then(() => {
129-
return this.http.get(
130-
this.apiUrl + '/settings/hideprofile',
131-
this.httpOptions
132-
);
133-
});
130+
async hideProfile() {
131+
await this.updateToken();
132+
let hideResponse = await firstValueFrom(this.http.get(
133+
this.apiUrl + '/settings/hideprofile',
134+
this.httpOptions
135+
));
136+
return hideResponse;
134137
}
135138

136139
/*
137140
* Keycloak account is created after succesful Suomi.fi authentication.
138141
* Delete this account if user cancels service deployment.
139142
*/
140143
async deleteAccount() {
141-
await this.updateToken({ bypassOrcidCheck: true }).then(() => {
142-
return this.http.delete(this.apiUrl + '/accountdelete/', this.httpOptions);
143-
});
144+
await this.updateToken({ bypassOrcidCheck: true });
145+
let deleteResponse = await firstValueFrom(this.http.delete(this.apiUrl + '/accountdelete/', this.httpOptions));
146+
return deleteResponse;
144147
}
145148

146149
async getOrcidData() {
147-
this.updateToken().then(() => {
148-
return this.http.get(this.apiUrl + '/orcid/', this.httpOptions);
149-
})
150+
await this.updateToken();
151+
let orcidData = await firstValueFrom(this.http.get(this.apiUrl + '/orcid/', this.httpOptions));
152+
return orcidData;
150153
}
151154

152155
async getProfileData(): Promise<any> {
@@ -169,34 +172,36 @@ export class ProfileService {
169172
await this.updateToken();
170173
let body = { groups: [], items: items };
171174

172-
let patch = await firstValueFrom(this.http.patch(
175+
let patchResponse = await firstValueFrom(this.http.patch(
173176
this.apiUrl + '/profiledata/',
174177
body,
175178
this.httpOptions
176179
));
177-
return patch;
180+
return patchResponse;
178181
}
179182

180183
async patchProfileDataSingleGroup(group) {
181-
await this.updateToken().then(() => {
182-
let body = { groups: group, items: [] };
183-
return this.http.patch(
184-
this.apiUrl + '/profiledata/',
185-
body,
186-
this.httpOptions
187-
);
188-
});
184+
await this.updateToken();
185+
let body = { groups: group, items: [] };
186+
187+
let patchResponse = await firstValueFrom(this.http.patch(
188+
this.apiUrl + '/profiledata/',
189+
body,
190+
this.httpOptions
191+
));
192+
return patchResponse;
189193
}
190194

191195
async patchProfileDataSingleItem(item) {
192-
await this.updateToken().then(() => {
193-
let body = { groups: [], items: item };
194-
return this.http.patch(
195-
this.apiUrl + '/profiledata/',
196-
body,
197-
this.httpOptions
198-
);
199-
});
196+
await this.updateToken();
197+
let body = { groups: [], items: item };
198+
199+
let patchResponse = await firstValueFrom(this.http.patch(
200+
this.apiUrl + '/profiledata/',
201+
body,
202+
this.httpOptions
203+
));
204+
return patchResponse;
200205
}
201206

202207
/*
@@ -205,8 +210,8 @@ export class ProfileService {
205210
* access and id tokens.
206211
*/
207212
async accountlink() {
208-
this.updateToken({ bypassOrcidCheck: true }).then(() => {
209-
return this.http.get(this.apiUrl + '/accountlink/', this.httpOptions);
210-
});
213+
await this.updateToken({ bypassOrcidCheck: true });
214+
let linkingResp = await firstValueFrom(this.http.get(this.apiUrl + '/accountlink/', this.httpOptions));
215+
return linkingResp;
211216
}
212217
}

0 commit comments

Comments
 (0)