Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions apps/backend/src/routes/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Prisma } from '@prisma/client';
import type {
FastifyInstance,
FastifyRequest,
Expand All @@ -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],
Comment thread
ramnnn2006 marked this conversation as resolved.
},
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);
Expand Down Expand Up @@ -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<{
Expand All @@ -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;
Expand Down