     1	import { parseJsonApiQuery } from '../lib/querying-writing/connectors-query-parser.js'
     2	
     3	export default async function registerRelationshipRoutes ({ context, api, log }) {
     4	  const { scopeName } = context
     5	  const basePath = api.scopes[scopeName].vars.transport?.mountPath || ''
     6	  const scopePath = `${basePath}/${scopeName}`
     7	
     8	  // Helper to create route handlers
     9	  const createRouteHandler = (methodName) => {
    10	    return async ({ params, body, queryString }) => {
    11	      const scope = api.scopes[scopeName]
    12	
    13	      const methodParams = {
    14	        id: params.id,
    15	        relationshipName: params.relationshipName,
    16	        isTransport: true
    17	      }
    18	
    19	      // Add query params for getRelated
    20	      if (methodName === 'getRelated' && queryString) {
    21	        methodParams.queryParams = parseJsonApiQuery(queryString)
    22	      }
    23	
    24	      // Add body data for write operations
    25	      if (body && body.data !== undefined) {
    26	        methodParams.relationshipData = body.data
    27	      }
    28	
    29	      return await scope[methodName](methodParams)
    30	    }
    31	  }
    32	
    33	  // Register relationship routes
    34	
    35	  // GET /api/{scope}/{id}/relationships/{relationshipName}
    36	  await api.addRoute({
    37	    method: 'GET',
    38	    path: `${scopePath}/:id/relationships/:relationshipName`,
    39	    handler: createRouteHandler('getRelationship')
    40	  })
    41	
    42	  // GET /api/{scope}/{id}/{relationshipName}
    43	  await api.addRoute({
    44	    method: 'GET',
    45	    path: `${scopePath}/:id/:relationshipName`,
    46	    handler: createRouteHandler('getRelated')
    47	  })
    48	
    49	  // POST /api/{scope}/{id}/relationships/{relationshipName}
    50	  await api.addRoute({
    51	    method: 'POST',
    52	    path: `${scopePath}/:id/relationships/:relationshipName`,
    53	    handler: createRouteHandler('postRelationship')
    54	  })
    55	
    56	  // PATCH /api/{scope}/{id}/relationships/{relationshipName}
    57	  await api.addRoute({
    58	    method: 'PATCH',
    59	    path: `${scopePath}/:id/relationships/:relationshipName`,
    60	    handler: createRouteHandler('patchRelationship')
    61	  })
    62	
    63	  // DELETE /api/{scope}/{id}/relationships/{relationshipName}
    64	  await api.addRoute({
    65	    method: 'DELETE',
    66	    path: `${scopePath}/:id/relationships/:relationshipName`,
    67	    handler: createRouteHandler('deleteRelationship')
    68	  })
    69	
    70	  log.trace(`Registered relationship routes for scope: ${scopeName}`)
    71	}
