Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

query owner email value from document

Marc Seitz86d1e4d19463
diff --git a/pages/api/views.ts b/pages/api/views.ts
index df8f51ee..5aa2c5f6 100644
--- a/pages/api/views.ts
+++ b/pages/api/views.ts
@@ -69,8 +69,12 @@ export default async function handle(
include: {
document: {
select: {
- ownerId: true,
name: true,
+ owner: {
+ select: {
+ email: true,
+ },
+ },
versions: {
where: { isPrimary: true },
orderBy: { createdAt: "desc" },
@@ -93,25 +97,13 @@ export default async function handle(
viewerEmail: email,
});
- // get document owner email
- const userEmail = await prisma.user.findUnique({
- where: {
- id: newView.document.ownerId,
- },
- select: {
- email: true,
- },
- });
-
- if (userEmail) {
- // send email to document owner that document has been viewed
- await sendViewedDocumentEmail(
- userEmail.email as string,
- documentId,
- newView.document.name,
- email
- );
- }
+ // send email to document owner that document has been viewed
+ await sendViewedDocumentEmail(
+ newView.document.owner.email as string,
+ documentId,
+ newView.document.name,
+ email
+ );
// check if document version has multiple pages, if so, return the pages
if (newView.document.versions[0].hasPages) {