Skip to content
20 changes: 3 additions & 17 deletions apps/backend/src/routes/profiles.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';

Check failure on line 1 in apps/backend/src/routes/profiles.ts

View workflow job for this annotation

GitHub Actions / backend-ci

`fastify` type import should occur after import of `../services/profileService`

Check failure on line 1 in apps/backend/src/routes/profiles.ts

View workflow job for this annotation

GitHub Actions / backend-ci

There should be at least one empty line between import groups
import { getProfileUrl } from '@devcard/shared';

Check failure on line 2 in apps/backend/src/routes/profiles.ts

View workflow job for this annotation

GitHub Actions / backend-ci

'getProfileUrl' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 2 in apps/backend/src/routes/profiles.ts

View workflow job for this annotation

GitHub Actions / backend-ci

There should be at least one empty line between import groups
import { updateProfileSchema, createLinkSchema, reorderLinksSchema } from '../utils/validators.js';

Check failure on line 3 in apps/backend/src/routes/profiles.ts

View workflow job for this annotation

GitHub Actions / backend-ci

`../utils/validators.js` import should occur after import of `../services/profileService`
import { getErrorMessage } from '../utils/error.util.js';
import * as profileService from '../services/profileService'

Check failure on line 4 in apps/backend/src/routes/profiles.ts

View workflow job for this annotation

GitHub Actions / backend-ci

'getErrorMessage' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 4 in apps/backend/src/routes/profiles.ts

View workflow job for this annotation

GitHub Actions / backend-ci

`../utils/error.util.js` import should occur after import of `../services/profileService`

// ── Response types ────────────────────────────────────────────────────────────
// Declared explicitly so the API contract is visible without tracing through
// Prisma's generic return types. Follows the convention in public.ts.

type ProfileUpdateResponse = {
id: string;
email: string;
username: string;
displayName: string;
bio: string | null;
pronouns: string | null;
role: string | null;
company: string | null;
avatarUrl: string | null;
accentColor: string;
};




export async function profileRoutes(app: FastifyInstance) {
// All profile routes require auth

Check failure on line 11 in apps/backend/src/routes/profiles.ts

View workflow job for this annotation

GitHub Actions / backend-ci

'ProfileUpdateResponse' is defined but never used. Allowed unused vars must match /^_/u
app.addHook('preHandler', async (request, reply) => {
const server = request.server as any;
if (typeof server?.authenticate === 'function') {
Expand All @@ -35,7 +21,7 @@
}
try {
await request.jwtVerify();
} catch (e) {

Check warning on line 24 in apps/backend/src/routes/profiles.ts

View workflow job for this annotation

GitHub Actions / backend-ci

Missing return type on function
reply.status(401).send({ error: 'Unauthorized' });
}
});
Expand All @@ -49,7 +35,7 @@
return user
});

// ─── Update Profile ───

Check failure on line 38 in apps/backend/src/routes/profiles.ts

View workflow job for this annotation

GitHub Actions / backend-ci

'e' is defined but never used. Allowed unused caught errors must match /^_/u

app.put('/me', async (request: FastifyRequest, reply: FastifyReply) => {
const userId = (request.user as any).id;
Expand All @@ -59,7 +45,7 @@
return reply.status(400).send({ error: 'Validation failed', details: parsed.error.flatten() });
}

// Fast-path uniqueness check. This read-before-write eliminates the common

Check failure on line 48 in apps/backend/src/routes/profiles.ts

View workflow job for this annotation

GitHub Actions / backend-ci

Expected { after 'if' condition
// case (clearly taken username) without touching the write path, but it
// cannot prevent the race window between two concurrent requests that both
// pass this check simultaneously. The unique constraint on the DB is the
Expand Down
Loading