fix: refactor

This commit is contained in:
David Nguyen
2024-05-01 15:14:00 +07:00
parent a25b9a372e
commit 1e825ede45

View File

@ -47,7 +47,11 @@ export const createDocumentFromTemplate = async ({
}, },
include: { include: {
Recipient: true, Recipient: true,
Field: true, Field: {
include: {
Recipient: true,
},
},
templateDocumentData: true, templateDocumentData: true,
}, },
}); });
@ -125,12 +129,10 @@ export const createDocumentFromTemplate = async ({
await tx.field.createMany({ await tx.field.createMany({
data: template.Field.map((field) => { data: template.Field.map((field) => {
const recipient = template.Recipient.find( const documentRecipient = document.Recipient.find(
(recipient) => recipient.id === field.recipientId, (recipient) => recipient.email === field.Recipient.email,
); );
const documentRecipient = document.Recipient.find((doc) => doc.email === recipient?.email);
if (!documentRecipient) { if (!documentRecipient) {
throw new Error('Recipient not found.'); throw new Error('Recipient not found.');
} }