2022-03-23 17:17:39 +01:00
|
|
|
import { FormControl } from '@angular/forms';
|
2022-04-01 13:18:05 +02:00
|
|
|
import { UserCreateRequest, UserUpdateRequest } from 'picsur-shared/dist/dto/api/usermanage.dto';
|
2022-03-23 17:17:39 +01:00
|
|
|
import {
|
|
|
|
|
CreatePasswordError,
|
|
|
|
|
CreateUsernameError,
|
|
|
|
|
PasswordValidators,
|
|
|
|
|
UsernameValidators
|
2022-03-28 17:12:35 +02:00
|
|
|
} from '../validators/user.validator';
|
2022-03-23 17:17:39 +01:00
|
|
|
|
|
|
|
|
export class UpdateUserControl {
|
2022-04-01 13:18:05 +02:00
|
|
|
private id: string = '';
|
2022-03-23 17:17:39 +01:00
|
|
|
public username = new FormControl('', UsernameValidators);
|
|
|
|
|
public password = new FormControl('', PasswordValidators);
|
2022-04-15 13:05:17 +02:00
|
|
|
public roles = new FormControl<string[]>([]);
|
2022-03-23 17:17:39 +01:00
|
|
|
|
|
|
|
|
public get usernameValue() {
|
|
|
|
|
return this.username.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public get usernameError() {
|
|
|
|
|
return CreateUsernameError(this.username.errors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public get passwordError() {
|
|
|
|
|
return CreatePasswordError(this.password.errors);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 22:12:06 +02:00
|
|
|
public get selectedRoles(): string[] {
|
2022-04-15 13:05:17 +02:00
|
|
|
return this.roles.value ?? [];
|
2022-03-23 19:29:40 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-23 17:17:39 +01:00
|
|
|
// Data interaction
|
|
|
|
|
|
2022-04-01 13:18:05 +02:00
|
|
|
public putId(id: string) {
|
|
|
|
|
this.id = id;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 17:17:39 +01:00
|
|
|
public putUsername(username: string) {
|
|
|
|
|
this.username.setValue(username);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public putRoles(roles: string[]) {
|
2022-03-28 22:12:06 +02:00
|
|
|
this.roles.setValue(roles);
|
2022-03-24 19:56:26 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-01 13:18:05 +02:00
|
|
|
public getDataCreate(): UserCreateRequest {
|
2022-03-23 17:17:39 +01:00
|
|
|
return {
|
2022-04-15 13:05:17 +02:00
|
|
|
username: this.username.value ?? '',
|
|
|
|
|
password: this.password.value ?? '',
|
2022-03-23 17:17:39 +01:00
|
|
|
roles: this.selectedRoles,
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-04-01 13:18:05 +02:00
|
|
|
|
|
|
|
|
public getDataUpdate(): UserUpdateRequest {
|
|
|
|
|
return {
|
|
|
|
|
...this.getDataCreate(),
|
|
|
|
|
id: this.id,
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-03-23 17:17:39 +01:00
|
|
|
}
|