From a044ead82513b3790c279328b0a10250386e15e1 Mon Sep 17 00:00:00 2001 From: Matteo Gheza Date: Tue, 2 Jan 2024 02:09:30 +0100 Subject: [PATCH] Refactor API calls in StatsServicesComponent --- .../stats-services.component.ts | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/frontend/src/app/_routes/stats/stats-services/stats-services.component.ts b/frontend/src/app/_routes/stats/stats-services/stats-services.component.ts index 10868ed..ce4f334 100644 --- a/frontend/src/app/_routes/stats/stats-services/stats-services.component.ts +++ b/frontend/src/app/_routes/stats/stats-services/stats-services.component.ts @@ -35,27 +35,22 @@ export class StatsServicesComponent implements OnInit { private toastr: ToastrService, private api: ApiClientService, private translate: TranslateService - ) { - this.api.get("list").then((users) => { - this.users = users; - console.log(this.users); + ) { } + + ngOnInit(): void { + 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) => { this.translate.get('edit_service.users_load_failed').subscribe((res: string) => { 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) {