@@ -83,31 +83,27 @@ router.get('/workspaces', (_req: Request, res: Response) => {
8383 res . json ( response ) ;
8484} ) ;
8585
86- // Middleware : resolve name-based slugs to workspace IDs.
86+ // Param middleware : resolve name-based slugs to workspace IDs.
8787// If the :workspaceId param is not a UUID, treat it as a slug and look up the matching workspace.
8888const UUID_RE = / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } $ / i;
8989
90- function resolveWorkspaceSlug ( req : Request , _res : Response , next : NextFunction ) {
91- const param = req . params . workspaceId ;
92- if ( UUID_RE . test ( param ) ) {
90+ router . param ( 'workspaceId' , ( req : Request , _res : Response , next : NextFunction , value : string ) => {
91+ if ( UUID_RE . test ( value ) ) {
9392 return next ( ) ; // Already a UUID, nothing to resolve
9493 }
9594
9695 // Treat param as a slug — find the first workspace whose name matches
9796 const workspaces = workspaceService . list ( ) ;
9897 const { slugToId } = buildSlugMap ( workspaces ) ;
99- const workspaceId = slugToId . get ( param ) ;
98+ const workspaceId = slugToId . get ( value ) ;
10099
101100 if ( ! workspaceId ) {
102101 return next ( new AppError ( 404 , 'Workspace not found' , 'WORKSPACE_NOT_FOUND' ) ) ;
103102 }
104103
105104 req . params . workspaceId = workspaceId ;
106105 next ( ) ;
107- }
108-
109- router . use ( '/:workspaceId/profile' , resolveWorkspaceSlug ) ;
110- router . use ( '/:workspaceId/starting-points' , resolveWorkspaceSlug ) ;
106+ } ) ;
111107
112108// Serve Marva profile JSON for a workspace
113109router . get ( '/:workspaceId/profile' , ( req : Request , res : Response , next : NextFunction ) => {
0 commit comments