Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix: properly return filteredViews from stats
Marc Seitz3782af5a4c47
diff --git a/pages/api/teams/[teamId]/documents/[id]/stats.ts b/pages/api/teams/[teamId]/documents/[id]/stats.tsindex 7edcfc35..ce2f45b0 100644--- a/pages/api/teams/[teamId]/documents/[id]/stats.ts+++ b/pages/api/teams/[teamId]/documents/[id]/stats.ts@@ -3,7 +3,6 @@ import { NextApiRequest, NextApiResponse } from "next";import { View } from "@prisma/client";import { getServerSession } from "next-auth/next";-import { LIMITS } from "@/lib/constants";import { errorhandler } from "@/lib/errorHandler";import prisma from "@/lib/prisma";import {@@ -81,14 +80,10 @@ export default async function handle(const activeViews = views.filter((view) => !view.isArchived);const archivedViews = views.filter((view) => view.isArchived);- // limit the number of views to 20 on free plan- const limitedViews =- document?.team?.plan === "free" ? views.slice(0, LIMITS.views) : views;-// exclude views from the team's memberslet internalViews: View[] = [];if (excludeTeamMembers) {- internalViews = limitedViews.filter((view) => {+ internalViews = activeViews.filter((view) => {return users.some((user) => user.email === view.viewerEmail);});}@@ -96,10 +91,12 @@ export default async function handle(// combined archived and internal viewsconst allExcludedViews = [...internalViews, ...archivedViews];- const filteredViews = limitedViews.filter(+ // filter out the excluded views+ const filteredViews = views.filter((view) => !allExcludedViews.map((view) => view.id).includes(view.id),);+ // get the reactions for the filtered viewsconst groupedReactions = await prisma.reaction.groupBy({by: ["type"],where: {@@ -132,7 +129,7 @@ export default async function handle((totalDocumentDuration.data[0].sum_duration * 1.0) /filteredViews.length,groupedReactions,- totalViews: activeViews.length,+ totalViews: filteredViews.length,};return res.status(200).json(stats);diff --git a/pages/api/teams/[teamId]/documents/[id]/views/[viewId]/stats.ts b/pages/api/teams/[teamId]/documents/[id]/views/[viewId]/stats.tsindex f300e5b3..ca4a68b4 100644--- a/pages/api/teams/[teamId]/documents/[id]/views/[viewId]/stats.ts+++ b/pages/api/teams/[teamId]/documents/[id]/views/[viewId]/stats.ts@@ -4,7 +4,6 @@ import { authOptions } from "@/pages/api/auth/[...nextauth]";import { getServerSession } from "next-auth/next";import { errorhandler } from "@/lib/errorHandler";-import prisma from "@/lib/prisma";import { getTeamWithUsersAndDocument } from "@/lib/team/helper";import { getViewPageDuration } from "@/lib/tinybird";import { CustomUser } from "@/lib/types";diff --git a/pages/api/teams/[teamId]/documents/[id]/views/index.ts b/pages/api/teams/[teamId]/documents/[id]/views/index.tsindex 5c935a61..3a3c9b0c 100644--- a/pages/api/teams/[teamId]/documents/[id]/views/index.ts+++ b/pages/api/teams/[teamId]/documents/[id]/views/index.ts@@ -6,7 +6,6 @@ import { getServerSession } from "next-auth/next";import { LIMITS } from "@/lib/constants";import { errorhandler } from "@/lib/errorHandler";import prisma from "@/lib/prisma";-import { getTeamWithUsersAndDocument } from "@/lib/team/helper";import { getViewPageDuration } from "@/lib/tinybird";import { CustomUser } from "@/lib/types";import { log } from "@/lib/utils";