Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: create viewer on document and dataroom visit
Marc Seitz84de252e560d
diff --git a/pages/api/views-dataroom.ts b/pages/api/views-dataroom.tsindex 84bfb189..424a719c 100644--- a/pages/api/views-dataroom.ts+++ b/pages/api/views-dataroom.ts@@ -113,14 +113,10 @@ export default async function handle(groupId: true,audienceType: true,allowDownload: true,- dataroom: {+ teamId: true,+ team: {select: {- teamId: true,- team: {- select: {- plan: true,- },- },+ plan: true,},},},@@ -438,7 +434,7 @@ export default async function handle(viewer = await prisma.viewer.findFirst({where: {email: email,- teamId: link.dataroom?.teamId,+ teamId: link.teamId!,},select: { id: true },});@@ -449,9 +445,8 @@ export default async function handle(viewer = await prisma.viewer.create({data: {email: email,- dataroomId: dataroomId!,verified: isEmailVerified,- teamId: link.dataroom?.teamId!,+ teamId: link.teamId!,},select: { id: true },});@@ -478,7 +473,7 @@ export default async function handle(dataroomId: dataroomId,viewType: "DATAROOM_VIEW",viewerId: viewer?.id ?? undefined,- teamId: link.dataroom?.teamId,+ teamId: link.teamId!,...(link.enableAgreement &&link.agreementId &&hasConfirmedAgreement && {@@ -578,8 +573,8 @@ export default async function handle(file: true,storageType: true,pageNumber: true,- embeddedLinks: !link.dataroom?.team.plan.includes("free"),- pageLinks: !link.dataroom?.team.plan.includes("free"),+ embeddedLinks: !link.team?.plan.includes("free"),+ pageLinks: !link.team?.plan.includes("free"),metadata: true,},});diff --git a/pages/api/views.ts b/pages/api/views.tsindex 8623f1e0..127bc7a2 100644--- a/pages/api/views.ts+++ b/pages/api/views.ts@@ -95,14 +95,10 @@ export default async function handle(agreementId: true,enableWatermark: true,watermarkConfig: true,- document: {+ teamId: true,+ team: {select: {- teamId: true,- team: {- select: {- plan: true,- },- },+ plan: true,},},},@@ -389,6 +385,33 @@ export default async function handle(}try {+ let viewer: { id: string } | null = null;+ if (email && !isPreview) {+ // find or create a viewer+ console.time("find-viewer");+ viewer = await prisma.viewer.findFirst({+ where: {+ email: email,+ teamId: link.teamId!,+ },+ select: { id: true },+ });+ console.timeEnd("find-viewer");++ if (!viewer) {+ console.time("create-viewer");+ viewer = await prisma.viewer.create({+ data: {+ email: email,+ verified: isEmailVerified,+ teamId: link.teamId!,+ },+ select: { id: true },+ });+ console.timeEnd("create-viewer");+ }+ }+let newView: { id: string } | null = null;if (!isPreview) {console.time("create-view");@@ -398,7 +421,8 @@ export default async function handle(viewerEmail: email,viewerName: name,documentId: documentId,- teamId: link.document?.teamId,+ teamId: link.teamId!,+ viewerId: viewer?.id ?? undefined,verified: isEmailVerified,...(link.enableAgreement &&link.agreementId &&@@ -430,8 +454,8 @@ export default async function handle(file: true,storageType: true,pageNumber: true,- embeddedLinks: !link.document?.team.plan.includes("free"),- pageLinks: !link.document?.team.plan.includes("free"),+ embeddedLinks: !link.team?.plan.includes("free"),+ pageLinks: !link.team?.plan.includes("free"),metadata: true,},});