refactor(analytics): replace any casts with typed prehandler and prisma where clause (#546)#563
Conversation
|
@ramnnn2006 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 @ramnnn2006, 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 — All Checks PassedBackend — PASS
Mobile — SKIP
Web — SKIP
Last updated: |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR tightens authentication handling and TypeScript typings for Fastify JWT-authenticated analytics endpoints.
Changes:
- Added Fastify module augmentations for
app.authenticateand JWTrequest.usertyping. - Replaced inline JWT verification preHandlers with a shared
app.authenticatepreHandler. - Improved Prisma typing for the analytics
/viewsquerywhereclause.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/backend/src/types/fastify.d.ts | Adds Fastify/JWT type augmentations for authentication and typed request.user. |
| apps/backend/src/routes/analytics.ts | Uses app.authenticate for route protection and strengthens Prisma where typing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Congratulations @ramnnn2006 on getting PR #563 merged! Thank you for your contribution to the project. To receive the appropriate GSSoC labels and recognition, please mention @Harxhit in the #get-labels channel on our Discord server and share your merged PR link. |
Summary
the pr removes the remaining
anyusages in the analytics routes and replaces the hand-rolled inline auth preHandler with the sharedapp.authenticatedecorator, sorequest.userand the prisma where clause are properly typed instead of cast toany. this is the analytics.ts slice of the type-safety umbrella.Fixes #546
Type of Change
What Changed
request.server as anyand(app as any).authenticateand fell back to a manualjwtVerify) withpreHandler: [app.authenticate], the same decorator the rest of the backend uses.(request.user as any).id/.usernamecasts inapps/backend/src/routes/analytics.tsand usedrequest.user.id/request.user.usernamedirectly.Prisma.CardViewWhereInputinstead ofconst whereClause: any, withimport type { Prisma } from '@prisma/client'.apps/backend/src/types/fastify.d.ts, declared theauthenticatedecorator onFastifyInstanceand augmented@fastify/jwt'sFastifyJWTsorequest.usercarries{ id, username }. went throughFastifyJWTrather than augmentingFastifyRequest.userdirectly because@fastify/jwtalready owns that field.How to Test
npm run typecheck -w apps/backendpasses with no errors.npx eslint src/routes/analytics.tsis clean).GET /api/analytics/overviewandGET /api/analytics/viewswith a valid token and confirm they still return the same data, and that an unauthenticated request still gets a 401. behaviour is unchanged, this is types and a swap to the shared auth decorator.Checklist
npm run typecheck).console.logor debug statements left in the code.Screenshots / Recordings
n/a, no ui changes.
Additional Context
scope here is just analytics.ts plus the shared fastify type file, matching #546. the other files in the umbrella (cards, connect, event, etc) have their own sub-issues so they're out of scope. note the template's checklist commands say
pnpmbut the repo moved to npm workspaces, so i ran the npm equivalents