diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a7d430e..36e93caf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,12 @@ jobs: - name: Install backend dependencies run: npm --prefix apps/backend install + - name: Install shared dependencies + run: npm --prefix packages/shared install + - name: Build shared package + run: npm --prefix packages/shared run build + - name: DB migration check if: needs.detect-changes.outputs.dbFiles != '' continue-on-error: true diff --git a/apps/backend/src/routes/cards.ts b/apps/backend/src/routes/cards.ts index 694cbec3..96125215 100644 --- a/apps/backend/src/routes/cards.ts +++ b/apps/backend/src/routes/cards.ts @@ -62,7 +62,7 @@ function hasErrorCode( } export async function cardRoutes(app: FastifyInstance): Promise { - + // ─── List Cards ─── app.get('/', {preHandler: [(req, reply) => app.authenticate(req, reply)] },async (request: FastifyRequest, reply: FastifyReply): Promise => { const userId = request.user.id; @@ -85,10 +85,12 @@ export async function cardRoutes(app: FastifyInstance): Promise { try { const card = await cardService.createCard(app, userId, parsed.data) return reply.status(201).send(card) + } catch (error) { if (hasErrorCode(error, 'OWNERSHIP')) {return reply.status(403).send({ error: 'One or more links do not belong to your account' })} return handleDbError(error, request, reply) } + }); // ─── Update Card ─── @@ -103,10 +105,12 @@ export async function cardRoutes(app: FastifyInstance): Promise { const updated = await cardService.updateCard(app, userId, id, parsed.data) if (!updated) {return reply.status(404).send({ error: 'Card not found' })} return updated + } catch (error) { if (hasErrorCode(error, 'OWNERSHIP')) {return reply.status(403).send({ error: 'One or more links do not belong to your account' })} return handleDbError(error, request, reply) } + }); // ─── Delete Card ─── @@ -118,18 +122,21 @@ export async function cardRoutes(app: FastifyInstance): Promise { try { await cardService.deleteCard(app, userId, id) return reply.status(204).send() + } catch (error) { if (hasErrorCode(error, 'NOT_FOUND')) { return reply.status(404).send({ error: 'Card not found' }); } if (hasErrorCode(error, 'LAST_CARD')) { + return reply.status(400).send({ error: 'Cannot delete the last remaining card. A user must have at least one card.', }); } - return handleDbError(error, request, reply) - } + + return handleDbError(error, request, reply); + } }); // ─── Set Default Card ───