Modified user.component and user.service to be able to use default profile image (#22)

This commit is contained in:
Art
2021-09-21 16:02:15 +03:00
parent 78c3c05be2
commit 8c60c2b1e9
2 changed files with 8 additions and 7 deletions

View File

@ -77,8 +77,7 @@ export class UserComponent implements OnInit, OnDestroy {
}
public onAddNewUser(userForm: NgForm): void {
// TODO: test if profileImage is null (we are not passing it)
let formData = this.userService.createUserFormData('', userForm.value, this.profileImage!);
let formData = this.userService.createUserFormData(null, userForm.value, this.profileImage);
let subscription = this.userService.addUser(formData)
.subscribe(
(user: User) => {

View File

@ -63,19 +63,21 @@ export class UserService {
return [];
}
public createUserFormData(loggedInUsername: string, user: User, profileImage: File): FormData {
public createUserFormData(loggedInUsername: string | null, user: User, profileImage: File | null): FormData {
const formData = new FormData();
formData.append('currentUsername', loggedInUsername);
if (loggedInUsername)
formData.append('currentUsername', loggedInUsername);
formData.append('firstName', user.firstName);
formData.append('lastName', user.lastName);
formData.append("username", user.username);
formData.append("email", user.email);
formData.append("role", user.role);
formData.append("active", String(user.active));
formData.append("notLocked", String(user.notLocked));
formData.append("profileImage", profileImage);
formData.append("active", user.active ? 'true' : 'false');
formData.append("notLocked", user.notLocked ? 'true' : 'false');
if (profileImage)
formData.append("profileImage", profileImage);
return formData;
}