Skip to content
Snippets Groups Projects
Commit 308444f1 authored by alec.schmidt's avatar alec.schmidt
Browse files

misc changes and upgrades

parent d050b79b
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { User } from '../../Types/types';
import { UsersService } from '../../services/users.service';
import { AuthenticationService } from 'src/app/services/authentication.service';
@Component({
selector: 'app-update-user',
......@@ -10,33 +11,39 @@ import { UsersService } from '../../services/users.service';
})
export class UpdateUserComponent implements OnInit {
updateUser: FormGroup
updateUser: FormGroup;
@Input() user!: User;
@Output() closeModal: EventEmitter<void> = new EventEmitter<void>();
constructor(private userController: UsersService) { }
constructor(private userController: UsersService,
public auth: AuthenticationService) { }
ngOnInit(): void {
this.updateUser = new FormGroup({
username: new FormControl(this.user.username, Validators.required),
password: new FormControl('', Validators.required),
admin: new FormControl(this.user.admin, Validators.required)
});
}
onSubmit() {
const username = this.updateUser.get("username")!.value;
const password = this.updateUser.get("password")!.value;
const type = this.updateUser.get("admin")!.value;
const userToEdit: User = {
id: this.user.id,
username : username,
password: undefined,
password: password,
admin: type
}
if (this.auth.isAdmin())
this.userController.updateUser(userToEdit);
else
this.userController.updateUsername(userToEdit);
this.closeModal.emit();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment