Skip to content

Commit 91d41bb

Browse files
committed
Convert acceptedTermsOfService to accepted_terms_of_service
Todo: try find a way how to convert acceptedTermsOfService to accepted_terms_of_service in updateUserProfile more generic with mappers
1 parent d519a1d commit 91d41bb

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

src/app/core/services/user.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export class UserService {
5353
}
5454

5555
updateUserProfile(userId: string, key: string, data: ProfileSettingsUpdate): Observable<User> {
56-
const patchedData = key === ProfileSettingsKey.User ? data : { [key]: data };
56+
let data_formatted = ProfileSettingsKey.User && data.hasOwnProperty('acceptedTermsOfService') ? {accepted_terms_of_service: true} : data;
57+
const patchedData = key === ProfileSettingsKey.User ? data_formatted : { [key]: data_formatted };
5758

5859
return this.jsonApiService
5960
.patch<UserDataJsonApi>(`${this.apiUrl}/users/${userId}/`, {

src/app/core/store/user/user.state.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@ export class UserState {
263263
return;
264264
}
265265

266+
// Todo: try find a way how to convert acceptedTermsOfService to accepted_terms_of_service in updateUserProfile
267+
// more generic with mappers
268+
// const updatePayload: Partial<User> = {
269+
// acceptedTermsOfService: true,
270+
// };
271+
// const apiRequest = UserMapper.toAcceptedTermsOfServiceRequest(updatePayload);
272+
// .updateUserProfile(currentUser.id, ProfileSettingsKey.User, apiRequest)
273+
266274
return this.userService
267275
.updateUserProfile(currentUser.id, ProfileSettingsKey.User, { acceptedTermsOfService: true })
268276
.pipe(

src/app/shared/mappers/user/user.mapper.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
User,
2+
User, UserAcceptedTermsOfServiceJsonApi,
33
UserData,
44
UserDataJsonApi,
55
UserDataResponseJsonApi,
@@ -68,4 +68,11 @@ export class UserMapper {
6868
suffix: name.suffix ?? '',
6969
};
7070
}
71+
72+
static toAcceptedTermsOfServiceRequest(name: Partial<User>): UserAcceptedTermsOfServiceJsonApi {
73+
return {
74+
accepted_terms_of_service: name.acceptedTermsOfService ?? false,
75+
};
76+
}
77+
7178
}

src/app/shared/models/user/user.models.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,7 @@ export interface UserData {
105105
activeFlags: string[];
106106
currentUser: User | null;
107107
}
108+
109+
export interface UserAcceptedTermsOfServiceJsonApi {
110+
accepted_terms_of_service: boolean;
111+
}

0 commit comments

Comments
 (0)