11import { GrowthBook } from '@growthbook/growthbook'
2+ import moment from 'moment'
23import mongoose from 'mongoose'
34import { err , ok , okAsync , Result , ResultAsync } from 'neverthrow'
45import Mail from 'nodemailer/lib/mailer'
56
6- import { AutoReplyMailData , AutoreplySummaryRenderData } from 'src/app/services/mail/mail.types'
7- import MailService from '../../../services/mail/mail.service'
8- import * as EmailSubmissionService from '../email-submission/email-submission.service'
7+ import { AutoreplyPdfGenerationError } from 'src/app/services/mail/mail.errors'
8+ import {
9+ AutoReplyMailData ,
10+ AutoreplySummaryRenderData ,
11+ } from 'src/app/services/mail/mail.types'
12+ import { generateAutoreplyPdf } from 'src/app/services/mail/mail.utils'
913
1014import { featureFlags } from '../../../../../shared/constants'
1115import {
@@ -16,13 +20,15 @@ import {
1620} from '../../../../../shared/types'
1721import {
1822 EmailAdminDataField ,
19- FieldResponse , IEncryptedSubmissionSchema ,
23+ FieldResponse ,
24+ IEncryptedSubmissionSchema ,
2025 IPopulatedEncryptedForm ,
21- IPopulatedForm
26+ IPopulatedForm ,
2227} from '../../../../types'
2328import config from '../../../config/config'
2429import { createLoggerWithLabel } from '../../../config/logger'
2530import { getEncryptSubmissionModel } from '../../../models/submission.server.model'
31+ import MailService from '../../../services/mail/mail.service'
2632import { createQueryWithDateParam } from '../../../utils/date'
2733import { getMongoErrorMessage } from '../../../utils/handle-mongo-error'
2834import { DatabaseError , PossibleDatabaseError } from '../../core/core.errors'
@@ -35,6 +41,8 @@ import {
3541 WebhookValidationError ,
3642} from '../../webhook/webhook.errors'
3743import { WebhookFactory } from '../../webhook/webhook.factory'
44+ import { MYINFO_PREFIX } from '../email-submission/email-submission.constants'
45+ import * as EmailSubmissionService from '../email-submission/email-submission.service'
3846import { SubmissionEmailObj } from '../email-submission/email-submission.util'
3947import {
4048 ResponseModeError ,
@@ -43,13 +51,9 @@ import {
4351 UnsupportedSettingsError ,
4452} from '../submission.errors'
4553import { sendEmailConfirmations } from '../submission.service'
54+ import { ProcessedFieldResponse } from '../submission.types'
4655import { extractEmailConfirmationData } from '../submission.utils'
4756
48- import moment from 'moment'
49- import { AutoreplyPdfGenerationError } from 'src/app/services/mail/mail.errors'
50- import { generateAutoreplyPdf } from 'src/app/services/mail/mail.utils'
51- import { MYINFO_PREFIX } from '../email-submission/email-submission.constants'
52- import { ProcessedFieldResponse } from '../submission.types'
5357import { CHARTS_MAX_SUBMISSION_RESULTS } from './encrypt-submission.constants'
5458import { SaveEncryptSubmissionParams } from './encrypt-submission.types'
5559
@@ -107,10 +111,10 @@ export const assertFormIsSingleSubmissionDisabled = (
107111 return ! form . isSingleSubmission
108112 ? ok ( form )
109113 : err (
110- new UnsupportedSettingsError (
111- 'isSingleSubmission cannot be enabled for payment forms as it is not currently supported' ,
112- ) ,
113- )
114+ new UnsupportedSettingsError (
115+ 'isSingleSubmission cannot be enabled for payment forms as it is not currently supported' ,
116+ ) ,
117+ )
114118}
115119
116120/**
@@ -151,7 +155,10 @@ const checkIfRespondentFormSummaryIsRequired = ({
151155 autoReplyMailDatas : AutoReplyMailData [ ]
152156 isPaymentEnabled : boolean
153157} ) : boolean => {
154- return ! isPaymentEnabled && autoReplyMailDatas . some ( ( data ) => data . includeFormSummary )
158+ return (
159+ ! isPaymentEnabled &&
160+ autoReplyMailDatas . some ( ( data ) => data . includeFormSummary )
161+ )
155162}
156163
157164const checkIfPdfGenerationIsRequired = ( {
@@ -161,10 +168,13 @@ const checkIfPdfGenerationIsRequired = ({
161168 isPaymentEnabled : boolean
162169 autoReplyMailDatas : AutoReplyMailData [ ]
163170} ) : boolean => {
164- return checkIfAdminPdfIsRequired ( ) || checkIfRespondentFormSummaryIsRequired ( {
165- isPaymentEnabled,
166- autoReplyMailDatas,
167- } )
171+ return (
172+ checkIfAdminPdfIsRequired ( ) ||
173+ checkIfRespondentFormSummaryIsRequired ( {
174+ isPaymentEnabled,
175+ autoReplyMailDatas,
176+ } )
177+ )
168178}
169179
170180const generatePdfAttachmentIfRequired = ( {
@@ -182,10 +192,12 @@ const generatePdfAttachmentIfRequired = ({
182192 answer ?: EmailAdminDataField [ 'answer' ]
183193 } ) [ ]
184194} ) : ResultAsync < Mail . Attachment | undefined , AutoreplyPdfGenerationError > => {
185- if ( ! checkIfPdfGenerationIsRequired ( {
186- isPaymentEnabled,
187- autoReplyMailDatas,
188- } ) ) {
195+ if (
196+ ! checkIfPdfGenerationIsRequired ( {
197+ isPaymentEnabled,
198+ autoReplyMailDatas,
199+ } )
200+ ) {
189201 return okAsync ( undefined )
190202 }
191203
@@ -199,10 +211,7 @@ const generatePdfAttachmentIfRequired = ({
199211 formUrl : `${ config . app . appUrl } /${ form . _id } ` ,
200212 }
201213
202- return generateAutoreplyPdf (
203- renderData ,
204- true ,
205- ) . map ( ( pdfBuffer ) => ( {
214+ return generateAutoreplyPdf ( renderData , true ) . map ( ( pdfBuffer ) => ( {
206215 filename : 'response.pdf' ,
207216 content : Buffer . copyBytesFrom ( pdfBuffer ) ,
208217 } ) )
@@ -284,11 +293,11 @@ export const performEncryptPostSubmissionActions = ({
284293 . andThen ( ( form ) => {
285294 const respondentCopyEmailData : AutoReplyMailData [ ] = respondentEmails
286295 ? respondentEmails ?. map ( ( val ) => {
287- return {
288- email : val ,
289- includeFormSummary : true ,
290- }
291- } )
296+ return {
297+ email : val ,
298+ includeFormSummary : true ,
299+ }
300+ } )
292301 : [ ]
293302
294303 // TODO [PDF-LAMBDA-GENERATION]: Remove setting of Growthbook targetting once pdf generation rollout is complete
@@ -342,7 +351,8 @@ export const performEncryptPostSubmissionActions = ({
342351
343352 return pdfAttachmentResult . andThen ( ( pdfAttachment ) => {
344353 void MailService . sendSubmissionToAdmin ( {
345- replyToEmails : EmailSubmissionService . extractEmailAnswers ( emailFields ) ,
354+ replyToEmails :
355+ EmailSubmissionService . extractEmailAnswers ( emailFields ) ,
346356 form,
347357 submission : {
348358 created : submission . created ,
@@ -351,7 +361,9 @@ export const performEncryptPostSubmissionActions = ({
351361 attachments,
352362 formData : emailData . formData ,
353363 dataCollationData,
354- pdfAttachment : checkIfAdminPdfIsRequired ( ) ? pdfAttachment : undefined ,
364+ pdfAttachment : checkIfAdminPdfIsRequired ( )
365+ ? pdfAttachment
366+ : undefined ,
355367 } )
356368
357369 return sendEmailConfirmations ( {
@@ -363,7 +375,9 @@ export const performEncryptPostSubmissionActions = ({
363375 pdfAttachment : checkIfRespondentFormSummaryIsRequired ( {
364376 isPaymentEnabled,
365377 autoReplyMailDatas : recipientEmailDatas ,
366- } ) ? pdfAttachment : undefined ,
378+ } )
379+ ? pdfAttachment
380+ : undefined ,
367381 isPaymentEnabled,
368382 } ) . mapErr ( ( error ) => {
369383 logger . error ( {
0 commit comments