@@ -4,6 +4,20 @@ import type { Card } from '@devcard/shared';
44import { createCardSchema , updateCardSchema } from '../utils/validators.js' ;
55import { handleDbError } from '../utils/error.util.js' ;
66
7+ interface CreateCardBody {
8+ title : string ;
9+ linkIds : string [ ] ;
10+ }
11+
12+ interface UpdateCardBody {
13+ title ?: string ;
14+ linkIds ?: string [ ] ;
15+ }
16+
17+ interface CardParams {
18+ id : string ;
19+ }
20+
721export async function cardRoutes ( app : FastifyInstance ) : Promise < void > {
822 app . addHook ( 'preHandler' , app . authenticate ) ;
923
@@ -38,7 +52,7 @@ export async function cardRoutes(app: FastifyInstance): Promise<void> {
3852
3953 // ─── Create Card ───
4054
41- app . post ( '/' , async ( request : FastifyRequest , reply : FastifyReply ) : Promise < Card | void > => {
55+ app . post ( '/' , async ( request : FastifyRequest < { Body : CreateCardBody } > , reply : FastifyReply ) : Promise < Card | void > => {
4256 const userId = ( request . user as { id : string } ) . id ;
4357 const parsed = createCardSchema . safeParse ( request . body ) ;
4458
@@ -82,7 +96,7 @@ export async function cardRoutes(app: FastifyInstance): Promise<void> {
8296
8397 // ─── Update Card ───
8498
85- app . put ( '/:id' , async ( request : FastifyRequest < { Params : { id : string } } > , reply : FastifyReply ) : Promise < Card | void > => {
99+ app . put ( '/:id' , async ( request : FastifyRequest < { Params : CardParams ; Body : UpdateCardBody } > , reply : FastifyReply ) : Promise < Card | void > => {
86100 const userId = ( request . user as { id : string } ) . id ;
87101 const { id } = request . params ;
88102
@@ -157,7 +171,7 @@ export async function cardRoutes(app: FastifyInstance): Promise<void> {
157171
158172 // ─── Delete Card ───
159173
160- app . delete ( '/:id' , async ( request : FastifyRequest < { Params : { id : string } } > , reply : FastifyReply ) : Promise < void > => {
174+ app . delete ( '/:id' , async ( request : FastifyRequest < { Params : CardParams } > , reply : FastifyReply ) : Promise < void > => {
161175 const userId = ( request . user as { id : string } ) . id ;
162176 const { id } = request . params ;
163177
@@ -200,7 +214,7 @@ export async function cardRoutes(app: FastifyInstance): Promise<void> {
200214
201215 // ─── Set Default Card ───
202216
203- app . put ( '/:id/default' , async ( request : FastifyRequest < { Params : { id : string } } > , reply : FastifyReply ) : Promise < object | void > => {
217+ app . put ( '/:id/default' , async ( request : FastifyRequest < { Params : CardParams } > , reply : FastifyReply ) : Promise < object | void > => {
204218 const userId = ( request . user as { id : string } ) . id ;
205219 const { id } = request . params ;
206220
0 commit comments