fix(event): remove all any casts — typed authenticate, user.id, and Prisma error narrowing#595
fix(event): remove all any casts — typed authenticate, user.id, and Prisma error narrowing#595Srejoye wants to merge 4 commits into
any casts — typed authenticate, user.id, and Prisma error narrowing#595Conversation
…arrowing
- Replace 3×
equest.server as any / (app as any).authenticate preHandler boilerplate with �pp.authenticate — already declared on FastifyInstance in src/types/fastify.d.ts, consistent with follow.ts / team.ts pattern
- Replace 3× (request.user as any).id with
equest.user.id — covered by the FastifyJWT augmentation (user: { id: string; username: string })
- Replace 2× catch (error: any) with catch (error: unknown) + instanceof Prisma.PrismaClientKnownRequestError narrowing before .code access (P2002 join-duplicate → 409, P2025 leave-not-found → 404)
- Replace (error as Error).message with getErrorMessage(error) from the shared error utility already used in follow.ts / connect.ts
- Update event.test.ts: construct Prisma error mocks with
ew Prisma.PrismaClientKnownRequestError(...) so instanceof narrowing resolves correctly in tests; import Prisma alongside PrismaClient
|
@Srejoye is attempting to deploy a commit to the Prashantkumar Khatri's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @Srejoye, Thanks for opening this pull request. This PR has been automatically classified based on the files modified. Applied Labels
Primary Review Area
Reviewer@Harxhit has been identified as the primary reviewer for this pull request. If you have any questions regarding the affected area or implementation details, feel free to reach out to the assigned reviewer. Thank you for your contribution! |
CI — Checks FailedBackend — FAIL
Mobile — SKIP
Web — SKIP
Last updated: |
|
@Harxhit I fixed the lint issues in
After the changes:
Since my changes are lint-only and do not modify the route logic or test behavior, these test failures appear to be unrelated to the lint fixes introduced in this PR. |
Summary
Eliminates all
anyusage fromapps/backend/src/routes/event.tsas part of #541.Changes
src/routes/event.ts/, POST/:slug/join, DELETE/:slug/leavepreHandlersrequest.server as any/(app as any).authenticatedefensive boilerplateapp.authenticate— already declared onFastifyInstanceinfastify.d.ts(request.user as any).idrequest.user.id— typed viaFastifyJWTaugmentation (user: AuthenticatedUser)catch (error: any)→error.codedirect accesscatch (error: unknown)+instanceof Prisma.PrismaClientKnownRequestErrorbefore.codecheck(error as Error).messagegetErrorMessage(error)from sharederror.util.tssrc/__tests__/event.test.tsPrismaalongsidePrismaClientnew Prisma.PrismaClientKnownRequestError(msg, { code, clientVersion })soinstanceofnarrowing in the route resolves correctlysrc/types/fastify.d.tsNo changes —
FastifyInstance.authenticateandFastifyJWT.user: AuthenticatedUserwere already declared; this PR reuses them.Verification
tsc --noEmitpasses with zeroanyremaining inevent.tsevent.test.tspass:/→ 201 (create), 401 (unauth), 400 (validation), 500 (db error)/:slug→ 200, 404/:slug/join→ 201, 401, 404, 409 (P2002 viaPrismaClientKnownRequestError), 500/:slug/leave→ 204, 401, 404, 404 (P2025 viaPrismaClientKnownRequestError), 500/:slug/attendees→ pagination, cap, orderingRelated
Closes #549