@@ -62,7 +62,7 @@ function hasErrorCode(
6262}
6363
6464export async function cardRoutes ( app : FastifyInstance ) : Promise < void > {
65-
65+
6666 // ─── List Cards ───
6767 app . get ( '/' , { preHandler : [ ( req , reply ) => app . authenticate ( req , reply ) ] } , async ( request : FastifyRequest , reply : FastifyReply ) : Promise < CardResponse [ ] | void > => {
6868 const userId = request . user . id ;
@@ -85,10 +85,12 @@ export async function cardRoutes(app: FastifyInstance): Promise<void> {
8585 try {
8686 const card = await cardService . createCard ( app , userId , parsed . data )
8787 return reply . status ( 201 ) . send ( card )
88+
8889 } catch ( error ) {
8990 if ( hasErrorCode ( error , 'OWNERSHIP' ) ) { return reply . status ( 403 ) . send ( { error : 'One or more links do not belong to your account' } ) }
9091 return handleDbError ( error , request , reply )
9192 }
93+
9294 } ) ;
9395
9496 // ─── Update Card ───
@@ -103,10 +105,12 @@ export async function cardRoutes(app: FastifyInstance): Promise<void> {
103105 const updated = await cardService . updateCard ( app , userId , id , parsed . data )
104106 if ( ! updated ) { return reply . status ( 404 ) . send ( { error : 'Card not found' } ) }
105107 return updated
108+
106109 } catch ( error ) {
107110 if ( hasErrorCode ( error , 'OWNERSHIP' ) ) { return reply . status ( 403 ) . send ( { error : 'One or more links do not belong to your account' } ) }
108111 return handleDbError ( error , request , reply )
109112 }
113+
110114 } ) ;
111115
112116 // ─── Delete Card ───
@@ -118,18 +122,21 @@ export async function cardRoutes(app: FastifyInstance): Promise<void> {
118122 try {
119123 await cardService . deleteCard ( app , userId , id )
120124 return reply . status ( 204 ) . send ( )
125+
121126 } catch ( error ) {
122127 if ( hasErrorCode ( error , 'NOT_FOUND' ) ) {
123128 return reply . status ( 404 ) . send ( { error : 'Card not found' } ) ;
124129 }
125130
126131 if ( hasErrorCode ( error , 'LAST_CARD' ) ) {
132+
127133 return reply . status ( 400 ) . send ( {
128134 error : 'Cannot delete the last remaining card. A user must have at least one card.' ,
129135 } ) ;
130136 }
131- return handleDbError ( error , request , reply )
132- }
137+
138+ return handleDbError ( error , request , reply ) ;
139+ }
133140 } ) ;
134141
135142 // ─── Set Default Card ───
0 commit comments