mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
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.
64 lines
1.4 KiB
TypeScript
64 lines
1.4 KiB
TypeScript
import { EnvelopeType, FieldType, RecipientRole, SigningStatus } from '@prisma/client';
|
|
|
|
import { prisma } from '@documenso/prisma';
|
|
|
|
export type GetFieldsForTokenOptions = {
|
|
token: string;
|
|
};
|
|
|
|
// Note: You many need to filter this on a per envelope item ID basis.
|
|
export const getFieldsForToken = async ({ token }: GetFieldsForTokenOptions) => {
|
|
if (!token) {
|
|
throw new Error('Missing token');
|
|
}
|
|
|
|
const recipient = await prisma.recipient.findFirst({
|
|
where: { token },
|
|
});
|
|
|
|
if (!recipient) {
|
|
return [];
|
|
}
|
|
|
|
if (recipient.role === RecipientRole.ASSISTANT) {
|
|
return await prisma.field.findMany({
|
|
where: {
|
|
OR: [
|
|
{
|
|
type: {
|
|
not: FieldType.SIGNATURE,
|
|
},
|
|
recipient: {
|
|
signingStatus: {
|
|
not: SigningStatus.SIGNED,
|
|
},
|
|
signingOrder: {
|
|
gte: recipient.signingOrder ?? 0,
|
|
},
|
|
},
|
|
envelope: {
|
|
id: recipient.envelopeId,
|
|
type: EnvelopeType.DOCUMENT,
|
|
},
|
|
},
|
|
{
|
|
recipientId: recipient.id,
|
|
},
|
|
],
|
|
},
|
|
include: {
|
|
signature: true,
|
|
},
|
|
});
|
|
}
|
|
|
|
return await prisma.field.findMany({
|
|
where: {
|
|
recipientId: recipient.id,
|
|
},
|
|
include: {
|
|
signature: true,
|
|
},
|
|
});
|
|
};
|