Refactor API calls in StatsServicesComponent

This commit is contained in:
Matteo Gheza 2024-01-02 02:09:30 +01:00
parent de54931221
commit a044ead825
1 changed files with 11 additions and 16 deletions

View File

@ -35,27 +35,22 @@ export class StatsServicesComponent implements OnInit {
private toastr: ToastrService, private toastr: ToastrService,
private api: ApiClientService, private api: ApiClientService,
private translate: TranslateService private translate: TranslateService
) { ) { }
this.api.get("list").then((users) => {
this.users = users; ngOnInit(): void {
console.log(this.users); Promise.all([
this.api.get("list"),
this.api.get("service_types")
]).then((values: any[]) => {
this.users = values[0];
this.types = values[1];
this.loadServices();
}).catch((err) => { }).catch((err) => {
this.translate.get('edit_service.users_load_failed').subscribe((res: string) => { this.translate.get('edit_service.users_load_failed').subscribe((res: string) => {
this.toastr.error(res); this.toastr.error(res);
}); });
}); });
this.api.get("service_types").then((types) => {
console.log(types);
this.types = types;
}).catch((err) => {
this.translate.get('edit_service.types_load_failed').subscribe((res: string) => {
this.toastr.error(res);
});
});
}
ngOnInit(): void {
this.loadServices();
} }
getUserNameById(id: number) { getUserNameById(id: number) {