mirror of
https://github.com/documenso/documenso.git
synced 2025-11-21 20:21:38 +10:00
chore: disable next step on backend for signers without signature field
This commit is contained in:
@ -72,6 +72,22 @@ export const setFieldsForDocument = async ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that every signer has a signature field
|
||||||
|
const signers = document.recipients.filter((recipient) => recipient.role === 'SIGNER');
|
||||||
|
const hasEverySignerSignature = signers.every((signer) =>
|
||||||
|
fields.some(
|
||||||
|
(field) =>
|
||||||
|
(field.type === FieldType.SIGNATURE || field.type === FieldType.FREE_SIGNATURE) &&
|
||||||
|
field.recipientId === signer.id,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!hasEverySignerSignature) {
|
||||||
|
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
||||||
|
message: 'Every signer must have at least one signature field',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (document.completedAt) {
|
if (document.completedAt) {
|
||||||
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
||||||
message: 'Document already complete',
|
message: 'Document already complete',
|
||||||
|
|||||||
@ -58,12 +58,29 @@ export const setFieldsForTemplate = async ({
|
|||||||
teamId: null,
|
teamId: null,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
include: {
|
||||||
|
recipients: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!template) {
|
if (!template) {
|
||||||
throw new Error('Template not found');
|
throw new Error('Template not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that every signer has a signature field
|
||||||
|
const signers = template.recipients.filter((recipient) => recipient.role === 'SIGNER');
|
||||||
|
const hasEverySignerSignature = signers.every((signer) =>
|
||||||
|
fields.some(
|
||||||
|
(field) =>
|
||||||
|
(field.type === FieldType.SIGNATURE || field.type === FieldType.FREE_SIGNATURE) &&
|
||||||
|
field.signerId === signer.id,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!hasEverySignerSignature) {
|
||||||
|
throw new Error('Every signer must have at least one signature field');
|
||||||
|
}
|
||||||
|
|
||||||
const existingFields = await prisma.field.findMany({
|
const existingFields = await prisma.field.findMany({
|
||||||
where: {
|
where: {
|
||||||
templateId,
|
templateId,
|
||||||
|
|||||||
Reference in New Issue
Block a user