Skip to content

Commit

Permalink
finished default error alert 403
Browse files Browse the repository at this point in the history
  • Loading branch information
ailtonbsj committed Sep 5, 2022
1 parent d5f1831 commit 765df99
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export class AutorizacaoDatatableComponent implements OnInit {
next: _ => {
this.helper.alertSnack('Removido com sucesso!');
this.refreshComponent();
}
},
error: e => this.defaultError(e)
});
}

Expand Down Expand Up @@ -160,7 +161,7 @@ export class AutorizacaoDatatableComponent implements OnInit {
data["Dependência"] = instituicao.dependencia;
data["Entidade"] = instituicao.entidade;
data["Credenciamento"] = instituicao.credenciamento;

data["Validade do Credenciamento"] = HelperService.isoDateToBrazil(<any>instituicao.validadeCredenciamento);
data["Recredenciamento"] = instituicao.recredenciamento;
data["Validade do Recredenciamento"] = HelperService.isoDateToBrazil(<any>instituicao.validadeRecredenciamento);
Expand Down Expand Up @@ -232,4 +233,9 @@ export class AutorizacaoDatatableComponent implements OnInit {
});
}

defaultError(e: any) {
this.helper.alertSnack(
e.status == 403 ? 'Sem permissão para esta operação' : 'Ocorreu um erro');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,16 @@ export class AutorizacaoFormComponent implements OnInit {
next: () => {
this.helper.alertSnack('Inserido com sucesso.');
this.navigateToTable();
}
},
error: e => this.defaultError(e)
});
} else {
this.autorizacaoService.update(this.entity).subscribe({
next: () => {
this.helper.alertSnack('Atualizado com sucesso.');
this.navigateToTable();
}
},
error: e => this.defaultError(e)
});
}
} else this.form.markAllAsTouched();
Expand All @@ -136,4 +138,9 @@ export class AutorizacaoFormComponent implements OnInit {
this.router.navigate(['autorizacao']);
}

defaultError(e: any) {
this.helper.alertSnack(
e.status == 403 ? 'Sem permissão para esta operação' : 'Ocorreu um erro');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ export class ProcessoDatatableComponent implements OnInit {
this.helper.alertSnack('Removido com sucesso!');
this.refreshComponent();
},
error: e => {
this.helper.alertSnack(e);
}
error: e => this.defaultError(e)
});
}

Expand All @@ -88,4 +86,9 @@ export class ProcessoDatatableComponent implements OnInit {
});
}

defaultError(e: any) {
this.helper.alertSnack(
e.status == 403 ? 'Sem permissão para esta operação' : 'Ocorreu um erro');
}

}
10 changes: 8 additions & 2 deletions src/app/processo/processo-form/processo-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ export class ProcessoFormComponent implements OnInit {
next: () => {
this.helper.alertSnack('Inserido com sucesso.');
this.navigateToTable();
}
},
});
} else {
this.processoService.update(this.entity).subscribe({
next: () => {
this.helper.alertSnack('Atualizado com sucesso.');
this.navigateToTable();
}
},
error: e => this.defaultError(e)
});
}
} else this.form.markAllAsTouched();
Expand All @@ -113,4 +114,9 @@ export class ProcessoFormComponent implements OnInit {
this.router.navigate(['processo']);
}

defaultError(e: any) {
this.helper.alertSnack(
e.status == 403 ? 'Sem permissão para esta operação' : 'Ocorreu um erro');
}

}
3 changes: 2 additions & 1 deletion src/app/security/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ export class AuthService {
login(username: string, password: string) {
const credentials = { username, password };
this.http.post(`${this.api}/users/login`, credentials).subscribe({
next: () => {
next: (v: any) => {
localStorage.setItem('credentials', JSON.stringify(credentials));
localStorage.setItem('roles', JSON.stringify(v.roles.map((role: any) => role.name)));
AuthService.authSubject.next(true);
this.router.navigate(['/processo']);
},
Expand Down

0 comments on commit 765df99

Please sign in to comment.