diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e106d9..ea8b8ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,8 @@ Template for next version ### Fixed +- error sending notification when field is not defined (https://github.com/ohmyform/ohmyform/issues/161) + ### Security ## [1.0.1] - 2022-03-01 diff --git a/src/service/submission/submission.notification.service.ts b/src/service/submission/submission.notification.service.ts index 4c03460..4202b65 100644 --- a/src/service/submission/submission.notification.service.ts +++ b/src/service/submission/submission.notification.service.ts @@ -25,12 +25,12 @@ export class SubmissionNotificationService { try { const to = this.getEmail( submission, - notification.toField.id, + notification.toField?.id, notification.toEmail ) const from = this.getEmail( submission, - notification.fromField.id, + notification.fromField?.id, notification.fromEmail ) @@ -73,6 +73,10 @@ export class SubmissionNotificationService { } private getEmail(submission: SubmissionEntity, fieldId: number, fallback: string): string { + if (!fieldId) { + return fallback + } + const data = submission.fields.find(field => field.fieldId === fieldId)?.content if (!data) {