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
58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
import { prisma } from '@documenso/prisma';
|
|
import { FieldType } from '@documenso/prisma/client';
|
|
|
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
|
|
|
export interface GetRecipientsForAssistantOptions {
|
|
token: string;
|
|
}
|
|
|
|
export const getRecipientsForAssistant = async ({ token }: GetRecipientsForAssistantOptions) => {
|
|
const assistant = await prisma.recipient.findFirst({
|
|
where: {
|
|
token,
|
|
},
|
|
});
|
|
|
|
if (!assistant) {
|
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
message: 'Assistant not found',
|
|
});
|
|
}
|
|
|
|
let recipients = await prisma.recipient.findMany({
|
|
where: {
|
|
documentId: assistant.documentId,
|
|
signingOrder: {
|
|
gte: assistant.signingOrder ?? 0,
|
|
},
|
|
},
|
|
include: {
|
|
fields: {
|
|
where: {
|
|
OR: [
|
|
{
|
|
recipientId: assistant.id,
|
|
},
|
|
{
|
|
type: {
|
|
not: FieldType.SIGNATURE,
|
|
},
|
|
documentId: assistant.documentId,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
// Omit the token for recipients other than the assistant so
|
|
// it doesn't get sent to the client.
|
|
recipients = recipients.map((recipient) => ({
|
|
...recipient,
|
|
token: recipient.id === assistant.id ? token : '',
|
|
}));
|
|
|
|
return recipients;
|
|
};
|