Files
documenso/packages/lib/server-only/document/get-recipient-or-sender-by-share-link-slug.ts
David Nguyen 7f09ba72f4 feat: add envelopes (#2025)
This PR is handles the changes required to support envelopes. The new
envelope editor/signing page will be hidden during release.

The core changes here is to migrate the documents and templates model to
a centralized envelopes model.

Even though Documents and Templates are removed, from the user
perspective they will still exist as we remap envelopes to documents and
templates.
2025-10-14 21:56:36 +11:00

50 lines
916 B
TypeScript

import { prisma } from '@documenso/prisma';
export type GetRecipientOrSenderByShareLinkSlugOptions = {
slug: string;
};
export const getRecipientOrSenderByShareLinkSlug = async ({
slug,
}: GetRecipientOrSenderByShareLinkSlugOptions) => {
const { envelopeId, email } = await prisma.documentShareLink.findFirstOrThrow({
where: {
slug,
},
});
const sender = await prisma.user.findFirst({
where: {
envelopes: { some: { id: envelopeId } },
email,
},
select: {
email: true,
name: true,
signature: true,
},
});
if (sender) {
return sender;
}
const recipient = await prisma.recipient.findFirst({
where: {
envelopeId,
email,
},
select: {
email: true,
name: true,
signatures: true,
},
});
if (recipient) {
return recipient;
}
throw new Error('Recipient or sender not found');
};