chore: disable next step on backend for signers without signature field

This commit is contained in:
Catalin Pit
2025-02-13 13:57:20 +02:00
parent 763b7f82c9
commit bc2ec9a2d7
2 changed files with 33 additions and 0 deletions

View File

@ -58,12 +58,29 @@ export const setFieldsForTemplate = async ({
teamId: null,
}),
},
include: {
recipients: true,
},
});
if (!template) {
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({
where: {
templateId,