mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
## Description Introduces the ability for users with the **Assistant** role to prefill fields on behalf of other signers. Assistants can fill in various field types such as text, checkboxes, dates, and more, streamlining the document preparation process before it reaches the final signers. https://github.com/user-attachments/assets/c1321578-47ec-405b-a70a-7d9578385895
59 lines
1.2 KiB
TypeScript
59 lines
1.2 KiB
TypeScript
import { prisma } from '@documenso/prisma';
|
|
import { FieldType, RecipientRole, SigningStatus } from '@documenso/prisma/client';
|
|
|
|
export type GetFieldsForTokenOptions = {
|
|
token: string;
|
|
};
|
|
|
|
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,
|
|
},
|
|
},
|
|
documentId: recipient.documentId,
|
|
},
|
|
{
|
|
recipientId: recipient.id,
|
|
},
|
|
],
|
|
},
|
|
include: {
|
|
signature: true,
|
|
},
|
|
});
|
|
}
|
|
|
|
return await prisma.field.findMany({
|
|
where: {
|
|
recipientId: recipient.id,
|
|
},
|
|
include: {
|
|
signature: true,
|
|
},
|
|
});
|
|
};
|