@@ -22,11 +22,11 @@ import { type AuthEnv } from './auth.server.js'
2222
2323export async function resolve ( c : Context < AuthEnv > ) {
2424 const path = c . req . query ( 'path' )
25- if ( ! path ) return c . json ( { error : 'Missing path' } , 400 )
25+ if ( ! path ) return c . json ( { error : 'Missing path' , statusCode : 400 } , 400 )
2626
2727 // path = "ark:NAAN/shoulder+collection..."
2828 const arkLabelIdx = path . indexOf ( 'ark:' )
29- if ( arkLabelIdx === - 1 ) return c . json ( { error : 'Invalid ARK path' } , 400 )
29+ if ( arkLabelIdx === - 1 ) return c . json ( { error : 'Invalid ARK path' , statusCode : 400 } , 400 )
3030
3131 const afterLabel = path . slice ( arkLabelIdx + 4 ) // strip "ark:"
3232 const slashIdx = afterLabel . indexOf ( '/' )
@@ -322,11 +322,11 @@ export async function getArk(c: Context<AuthEnv>) {
322322 . innerJoin ( schema . organization , eq ( schema . collections . organizationId , schema . organization . id ) )
323323 . where ( and ( eq ( schema . organization . slug , owner ) , eq ( schema . collections . slug , slug ) ) )
324324 . limit ( 1 )
325- if ( ! coll ) return c . json ( { error : 'Collection not found' } , 404 )
325+ if ( ! coll ) return c . json ( { error : 'Collection not found' , statusCode : 404 } , 404 )
326326
327327 // Must be owner/member
328328 const hasAccess = await checkCollectionAccess ( coll . organizationId , c . get ( 'userId' ) ! )
329- if ( ! hasAccess ) return c . json ( { error : 'Forbidden' } , 403 )
329+ if ( ! hasAccess ) return c . json ( { error : 'Forbidden' , statusCode : 403 } , 403 )
330330
331331 const naan = coll . ownerNaan ?? DEFAULT_NAAN
332332
@@ -367,10 +367,10 @@ export async function updateArk(c: Context<AuthEnv>) {
367367 . innerJoin ( schema . organization , eq ( schema . collections . organizationId , schema . organization . id ) )
368368 . where ( and ( eq ( schema . organization . slug , owner ) , eq ( schema . collections . slug , slug ) ) )
369369 . limit ( 1 )
370- if ( ! coll ) return c . json ( { error : 'Collection not found' } , 404 )
370+ if ( ! coll ) return c . json ( { error : 'Collection not found' , statusCode : 404 } , 404 )
371371
372372 const hasAccess = await checkCollectionAccess ( coll . organizationId , c . get ( 'userId' ) ! )
373- if ( ! hasAccess ) return c . json ( { error : 'Forbidden' } , 403 )
373+ if ( ! hasAccess ) return c . json ( { error : 'Forbidden' , statusCode : 403 } , 403 )
374374
375375 const [ existing ] = await db
376376 . select ( { collectionId : schema . arkCollections . collectionId } )
@@ -415,10 +415,10 @@ export async function getArkRecordTypes(c: Context<AuthEnv>) {
415415 . innerJoin ( schema . organization , eq ( schema . collections . organizationId , schema . organization . id ) )
416416 . where ( and ( eq ( schema . organization . slug , owner ) , eq ( schema . collections . slug , slug ) ) )
417417 . limit ( 1 )
418- if ( ! coll ) return c . json ( { error : 'Collection not found' } , 404 )
418+ if ( ! coll ) return c . json ( { error : 'Collection not found' , statusCode : 404 } , 404 )
419419
420420 const hasAccess = await checkCollectionAccess ( coll . organizationId , c . get ( 'userId' ) ! )
421- if ( ! hasAccess ) return c . json ( { error : 'Forbidden' } , 403 )
421+ if ( ! hasAccess ) return c . json ( { error : 'Forbidden' , statusCode : 403 } , 403 )
422422
423423 const rows = await db
424424 . select ( {
@@ -436,18 +436,18 @@ export async function updateArkRecordTypes(c: Context<AuthEnv>) {
436436 const slug = c . req . param ( 'slug' ) !
437437 const { recordType, redirectUrlField } = await c . req . json ( )
438438
439- if ( ! recordType ) return c . json ( { error : 'recordType required' } , 400 )
439+ if ( ! recordType ) return c . json ( { error : 'recordType required' , statusCode : 400 } , 400 )
440440
441441 const [ coll ] = await db
442442 . select ( { id : schema . collections . id , organizationId : schema . collections . organizationId } )
443443 . from ( schema . collections )
444444 . innerJoin ( schema . organization , eq ( schema . collections . organizationId , schema . organization . id ) )
445445 . where ( and ( eq ( schema . organization . slug , owner ) , eq ( schema . collections . slug , slug ) ) )
446446 . limit ( 1 )
447- if ( ! coll ) return c . json ( { error : 'Collection not found' } , 404 )
447+ if ( ! coll ) return c . json ( { error : 'Collection not found' , statusCode : 404 } , 404 )
448448
449449 const hasAccess = await checkCollectionAccess ( coll . organizationId , c . get ( 'userId' ) ! )
450- if ( ! hasAccess ) return c . json ( { error : 'Forbidden' } , 403 )
450+ if ( ! hasAccess ) return c . json ( { error : 'Forbidden' , statusCode : 403 } , 403 )
451451
452452 if ( redirectUrlField === null ) {
453453 await db
@@ -478,15 +478,15 @@ export async function updateAccountArk(c: Context<AuthEnv>) {
478478 const { naan } = await c . req . json ( )
479479
480480 if ( naan !== null && ! / ^ \d { 1 , 16 } $ / . test ( naan ) ) {
481- return c . json ( { error : 'NAAN must be numeric (up to 16 digits)' } , 400 )
481+ return c . json ( { error : 'NAAN must be numeric (up to 16 digits)' , statusCode : 400 } , 400 )
482482 }
483483
484484 const [ org ] = await db
485485 . select ( { id : schema . organization . id } )
486486 . from ( schema . organization )
487487 . where ( eq ( schema . organization . slug , slug ) )
488488 . limit ( 1 )
489- if ( ! org ) return c . json ( { error : 'Org not found' } , 404 )
489+ if ( ! org ) return c . json ( { error : 'Org not found' , statusCode : 404 } , 404 )
490490
491491 // Must be owner/admin of the org
492492 const [ membership ] = await db
@@ -497,7 +497,7 @@ export async function updateAccountArk(c: Context<AuthEnv>) {
497497 )
498498 . limit ( 1 )
499499 if ( ! membership || ( membership . role !== 'owner' && membership . role !== 'admin' ) ) {
500- return c . json ( { error : 'Forbidden' } , 403 )
500+ return c . json ( { error : 'Forbidden' , statusCode : 403 } , 403 )
501501 }
502502
503503 await db
0 commit comments