Skip to content

Commit

Permalink
Merge pull request #55 from hlaff147/GPJ-34
Browse files Browse the repository at this point in the history
[GPJ-34] Atualiza edição de processos
  • Loading branch information
artn-dev authored May 11, 2022
2 parents 1f1729c + eceb217 commit b12f188
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ <h1 mat-dialog-title>Crie um processo</h1>
<mat-error *ngIf="judgeCpf.errors?.['length']" data-error="cpf-length">
CPF deve conter 11 dígitos.
</mat-error>
<mat-error *ngIf="judgeCpf.errors?.['fakeJudge']" data-error="cpf-length">
CPF deve ser de um juiz.
</mat-error>
</mat-form-field>
</div>
<div mat-dialog-actions class="d-flex justify-content-around w-100">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export class EditProcessComponent implements OnInit {
if (!this.status.valid) return;

this.userService.getUserByCpf(this.judgeCpf.value).subscribe((user) => {
if (user.role !== 'juiz') {
this.judgeCpf.setErrors({ fakeJudge: true });
return;
}

this.process.name = this.name.value;
this.process.judgeId = user.id;
this.process.status = this.status.value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
</p>

<button
*ngIf="user?.role == 'juiz'"
(click)="editProccess(process)"
class="border-0 ml-2 btn-icon btn-icon-only btn-pill btn btn-outline-focus btn-sm"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,7 @@ export class ProccessManagementComponent implements OnInit {
ngOnInit(): void {
this.userService.getCurrUser().subscribe((user) => {
this.user = user;

if (this.user.role === 'advogado') {
this.proccessService
.getProcessesByLawyer(this.user.id)
.subscribe((processes) => (this.processes = processes));
} else if (this.user.role === 'juiz') {
this.proccessService
.getProcessesByJudge(this.user.id)
.subscribe((processes) => (this.processes = processes));
}
this.getProcesses();
});
}

Expand Down Expand Up @@ -71,11 +62,33 @@ export class ProccessManagementComponent implements OnInit {
});

dialogRef.afterClosed().subscribe((result) => {
if (result !== undefined)
if (!result) return;

if (element) {
this.proccessService.editProcess(result).subscribe();
this.getProcesses();
} else {
this.proccessService
.addProcess(result)
.subscribe(
(process) => (this.processes = [process, ...this.processes])
);
}
});
}
editProccess(element: Process): void {
this.openModal(element);
}

getProcesses(): void {
if (this.user.role === 'advogado') {
this.proccessService
.getProcessesByLawyer(this.user.id)
.subscribe((processes) => (this.processes = processes));
} else if (this.user.role === 'juiz') {
this.proccessService
.getProcessesByJudge(this.user.id)
.subscribe((processes) => (this.processes = processes));
}
}
}

0 comments on commit b12f188

Please sign in to comment.