Commit 114eb5c0 authored by Tomáš Biloš's avatar Tomáš Biloš
Browse files

fix password on update

parent 22f59074
Pipeline #142535 failed with stage
in 16 seconds
<div *ngIf="agent">
<div *ngIf="errorMessage" class="text-red">{{ errorMessage }}</div>
<form [formGroup]="edit">
<mat-form-field>
<mat-label>Agent name</mat-label>
......@@ -35,7 +36,7 @@
</button>
<mat-form-field appearance="fill">
<mat-label>Favorite food</mat-label>
<mat-label>Agent role</mat-label>
<mat-select [(value)]="selectedRole">
<mat-option *ngFor="let role of roles" [value]="role">
{{ role }}
......
......@@ -23,18 +23,16 @@ export class EditAgentComponent implements OnInit {
roles = ['REGULAR', 'ADMIN', 'SUPERVISOR'];
selectedRole = 'REGULAR';
state: RequestState = RequestState.SUCCESS;
errorMessage: String = '';
errorMessage: String | undefined;
edit = new FormGroup({
name: new FormControl('', [
Validators.pattern(/[a-zA-Z]{3,}/),
Validators.required,
]),
training: new FormControl(''),
password: new FormControl('', [
Validators.required,
Validators.pattern(/.{6,}/),
]),
password: new FormControl(''),
});
creatingNewAgent = false;
skillColumns = ['skill'];
......@@ -92,24 +90,47 @@ export class EditAgentComponent implements OnInit {
this.agent!.skills = [...this.agent!.skills];
}
isPasswordValid() {
return this.edit.get('password')?.value?.length >= 6;
}
async saveAgent() {
if (this.creatingNewAgent && !this.isPasswordValid()) {
console.log(this.edit.get('password')?.value);
this.errorMessage = 'Invalid password';
return;
}
this.agent.name = this.edit.get('name')?.value;
this.agent.training = this.edit.get('training')?.value;
this.agent.agentRole = this.selectedRole;
this.agent.password = this.edit.get('password')?.value;
if (this.creatingNewAgent) {
this.agent = await firstValueFrom(
this.httpClient.post<Agent>(`${environment.apiUrl}/agents`, this.agent)
);
this.router.navigate(['auth', 'agents']);
try {
this.agent = await firstValueFrom(
this.httpClient.post<Agent>(
`${environment.apiUrl}/agents`,
this.agent
)
);
this.router.navigate(['auth', 'agents']);
} catch (error) {
this.errorMessage = 'Failed to create agent';
this.state = RequestState.ERROR;
}
} else {
this.agent = await firstValueFrom(
this.httpClient.put<Agent>(
`${environment.apiUrl}/agents/${this.agent.id}`,
this.agent
)
);
this.router.navigate(['auth', 'agent', this.agent.id]);
try {
this.agent = await firstValueFrom(
this.httpClient.put<Agent>(
`${environment.apiUrl}/agents/${this.agent.id}`,
this.agent
)
);
this.router.navigate(['auth', 'agent', this.agent.id]);
} catch (error) {
this.errorMessage = 'Failed to update agent';
this.state = RequestState.ERROR;
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment