fix: enhancements

This commit is contained in:
David Nguyen
2024-04-25 22:28:41 +07:00
parent ef666b0e70
commit 39bd3e5880
3 changed files with 57 additions and 48 deletions

View File

@ -56,13 +56,13 @@ export const createDocumentFromTemplate = async ({
throw new Error('Template not found.');
}
if (recipients.length === 0 || recipients.length !== template.Recipient.length) {
if (recipients.length !== template.Recipient.length) {
throw new Error('Invalid number of recipients.');
}
let finalRecipients: Pick<Recipient, 'name' | 'email' | 'role'>[] = [];
if (Object.prototype.hasOwnProperty.call(recipients[0], 'id')) {
if (recipients.length > 0 && Object.prototype.hasOwnProperty.call(recipients[0], 'id')) {
finalRecipients = template.Recipient.map((templateRecipient) => {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const foundRecipient = (recipients as RecipientWithId[]).find(