mirror of
https://github.com/documenso/documenso.git
synced 2025-11-20 03:32:14 +10:00
chore: allow document creation from template
This commit is contained in:
@ -256,10 +256,20 @@ export const createDocumentFromTemplate = async ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const recipientMapping = new Map<number, number>();
|
||||||
|
|
||||||
|
template.recipients.forEach((templateRecipient, index) => {
|
||||||
|
const documentRecipient = document.recipients[index];
|
||||||
|
if (documentRecipient) {
|
||||||
|
recipientMapping.set(templateRecipient.id, documentRecipient.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let fieldsToCreate: Omit<Field, 'id' | 'secondaryId' | 'templateId'>[] = [];
|
let fieldsToCreate: Omit<Field, 'id' | 'secondaryId' | 'templateId'>[] = [];
|
||||||
|
|
||||||
Object.values(finalRecipients).forEach(({ email, fields }) => {
|
finalRecipients.forEach(({ templateRecipientId, fields }) => {
|
||||||
const recipient = document.recipients.find((recipient) => recipient.email === email);
|
const documentRecipientId = recipientMapping.get(templateRecipientId);
|
||||||
|
const recipient = document.recipients.find((r) => r.id === documentRecipientId);
|
||||||
|
|
||||||
if (!recipient) {
|
if (!recipient) {
|
||||||
throw new Error('Recipient not found.');
|
throw new Error('Recipient not found.');
|
||||||
|
|||||||
Reference in New Issue
Block a user