Skip to content

Commit affea61

Browse files
authored
fix(cards): remove any usages in cards route (#621)
* fix(backend): remove any usages from cards.ts * fix: handle unknown errors in cards route * ci: build shared package before backend typecheck
1 parent 7d2918b commit affea61

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ jobs:
5858

5959
- name: Install backend dependencies
6060
run: npm --prefix apps/backend install
61+
- name: Install shared dependencies
62+
run: npm --prefix packages/shared install
6163

64+
- name: Build shared package
65+
run: npm --prefix packages/shared run build
66+
6267
- name: DB migration check
6368
if: needs.detect-changes.outputs.dbFiles != ''
6469
continue-on-error: true

apps/backend/src/routes/cards.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function hasErrorCode(
6262
}
6363

6464
export 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

Comments
 (0)