diff --git a/apps/backend/src/routes/analytics.ts b/apps/backend/src/routes/analytics.ts index efc22fe..884c052 100644 --- a/apps/backend/src/routes/analytics.ts +++ b/apps/backend/src/routes/analytics.ts @@ -1,3 +1,4 @@ +import type { Prisma } from '@prisma/client'; import type { FastifyInstance, FastifyRequest, @@ -12,14 +13,14 @@ export async function analyticsRoutes( '/overview', { // eslint-disable-next-line @typescript-eslint/unbound-method - preHandler: [async (request, reply) => { const server = request.server as any; if (typeof server?.authenticate === 'function') { await server.authenticate(request, reply); return } if (typeof (app as any).authenticate === 'function') { await (app as any).authenticate(request, reply); return } try { await request.jwtVerify() } catch (e) { reply.status(401).send({ error: 'Unauthorized' }) } }], + preHandler: [app.authenticate], }, async ( request: FastifyRequest, _reply: FastifyReply ) => { - const userId = (request.user as any).id; - const username = (request.user as any).username; + const userId = request.user.id; + const username = request.user.username; const today = new Date(); today.setHours(0, 0, 0, 0); @@ -98,7 +99,7 @@ export async function analyticsRoutes( '/views', { // eslint-disable-next-line @typescript-eslint/unbound-method - preHandler: [async (request, reply) => { const server = request.server as any; if (typeof server?.authenticate === 'function') { await server.authenticate(request, reply); return } if (typeof (app as any).authenticate === 'function') { await (app as any).authenticate(request, reply); return } try { await request.jwtVerify() } catch (e) { reply.status(401).send({ error: 'Unauthorized' }) } }], + preHandler: [app.authenticate], }, async ( request: FastifyRequest<{ @@ -109,12 +110,12 @@ export async function analyticsRoutes( }>, _reply: FastifyReply ) => { - const userId = (request.user as any).id; + const userId = request.user.id; const page = parseInt(request.query.page || '1', 10); const limit = 20; const skip = (page - 1) * limit; - const whereClause: any = { ownerId: userId }; + const whereClause: Prisma.CardViewWhereInput = { ownerId: userId }; if (request.query.cardId) { whereClause.cardId = request.query.cardId;