Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions frontend/src/app/guards/table-owner.guard.ts
Original file line number Diff line number Diff line change
@@ -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);
})
);
}
Loading