diff --git a/apps/backend/src/routes/cards.ts b/apps/backend/src/routes/cards.ts index 0f27e519..04ca1436 100644 --- a/apps/backend/src/routes/cards.ts +++ b/apps/backend/src/routes/cards.ts @@ -4,6 +4,20 @@ import type { Card } from '@devcard/shared'; import { createCardSchema, updateCardSchema } from '../utils/validators.js'; import { handleDbError } from '../utils/error.util.js'; +interface CreateCardBody { + title: string; + linkIds: string[]; +} + +interface UpdateCardBody { + title?: string; + linkIds?: string[]; +} + +interface CardParams { + id: string; +} + export async function cardRoutes(app: FastifyInstance): Promise { app.addHook('preHandler', app.authenticate); @@ -38,7 +52,7 @@ export async function cardRoutes(app: FastifyInstance): Promise { // ─── Create Card ─── - app.post('/', async (request: FastifyRequest, reply: FastifyReply): Promise => { + app.post('/', async (request: FastifyRequest<{ Body: CreateCardBody }>, reply: FastifyReply): Promise => { const userId = (request.user as { id: string }).id; const parsed = createCardSchema.safeParse(request.body); @@ -82,7 +96,7 @@ export async function cardRoutes(app: FastifyInstance): Promise { // ─── Update Card ─── - app.put('/:id', async (request: FastifyRequest<{ Params: { id: string } }>, reply: FastifyReply): Promise => { + app.put('/:id', async (request: FastifyRequest<{ Params: CardParams; Body: UpdateCardBody }>, reply: FastifyReply): Promise => { const userId = (request.user as { id: string }).id; const { id } = request.params; @@ -157,7 +171,7 @@ export async function cardRoutes(app: FastifyInstance): Promise { // ─── Delete Card ─── - app.delete('/:id', async (request: FastifyRequest<{ Params: { id: string } }>, reply: FastifyReply): Promise => { + app.delete('/:id', async (request: FastifyRequest<{ Params: CardParams }>, reply: FastifyReply): Promise => { const userId = (request.user as { id: string }).id; const { id } = request.params; @@ -200,7 +214,7 @@ export async function cardRoutes(app: FastifyInstance): Promise { // ─── Set Default Card ─── - app.put('/:id/default', async (request: FastifyRequest<{ Params: { id: string } }>, reply: FastifyReply): Promise => { + app.put('/:id/default', async (request: FastifyRequest<{ Params: CardParams }>, reply: FastifyReply): Promise => { const userId = (request.user as { id: string }).id; const { id } = request.params;