From 2c76b9844ff3af8b2d8f6b01ab9fbef8e2e30400 Mon Sep 17 00:00:00 2001 From: icsp Date: Fri, 6 Jun 2025 19:52:40 +0200 Subject: [PATCH] - Implement tableOwnerGuard guard. --- frontend/src/app/guards/table-owner.guard.ts | 26 ++++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/frontend/src/app/guards/table-owner.guard.ts b/frontend/src/app/guards/table-owner.guard.ts index ad5fac72..09269177 100644 --- a/frontend/src/app/guards/table-owner.guard.ts +++ b/frontend/src/app/guards/table-owner.guard.ts @@ -1,18 +1,18 @@ import {CanActivateFn, Router} from '@angular/router'; import {inject} from '@angular/core'; -import {HomeService} from '../home/home.service'; -import {catchError, of} from 'rxjs'; +import {TableApiService} from '../services/table-api.service'; +import {catchError, map, of} from 'rxjs'; - -// TODO: valutare se implementarla export const tableOwnerGuard: CanActivateFn = (route, _) => { - // const tableId: string = route.paramMap.get('table-id') || ''; - // const router: Router = inject(Router); - // - // return inject(HomeService).currentUserHasTable(tableId).pipe( - // catchError(() => - // of(router.createUrlTree([`/tables/${tableId}`])) - // ) - // ); - return true; + const tableId = route.url[route.url.length - 1].toString(); + const tableApi = inject(TableApiService); + const router = inject(Router); + + return tableApi.getTable(tableId).pipe( + map(() => true), + catchError((_) => { + router.navigate([`${ tableId }`]).then(); + return of(false); + }) + ); }