2022-03-23 17:17:39 +01:00
|
|
|
import { FormControl } from '@angular/forms';
|
2022-03-28 17:26:50 +02:00
|
|
|
import { FullUserModel } from '../forms-dto/fulluser.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 {
|
|
|
|
|
public username = new FormControl('', UsernameValidators);
|
|
|
|
|
public password = new FormControl('', PasswordValidators);
|
2022-03-28 22:12:06 +02:00
|
|
|
public roles = new FormControl([]);
|
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[] {
|
|
|
|
|
return this.roles.value;
|
2022-03-23 19:29:40 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-23 17:17:39 +01:00
|
|
|
// Data interaction
|
|
|
|
|
|
|
|
|
|
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-03-23 17:17:39 +01:00
|
|
|
public getData(): FullUserModel {
|
|
|
|
|
return {
|
|
|
|
|
username: this.username.value,
|
|
|
|
|
password: this.password.value,
|
|
|
|
|
roles: this.selectedRoles,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|