Skip to content

Commit

Permalink
fix: fix issue where email notifs for storage forms have wrong submis…
Browse files Browse the repository at this point in the history
…sion id
  • Loading branch information
g-tejas committed Jun 20, 2024
1 parent 4cde729 commit 99fa925
Showing 1 changed file with 39 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,41 +280,6 @@ const submitEncryptModeForm = async (
}
}

const logMetaWithSubmission = {
...logMeta,
submissionId: form._id,
responseMetadata,
}

logger.info({
message: 'Sending admin notification mail',
meta: logMetaWithSubmission,
})

const emailData = new SubmissionEmailObj(
req.body.responses,
new Set(), // the MyInfo prefixes are already inserted in middleware
form.authType,
)

// We don't await for email submission, as the submission gets saved for encrypt
// submissions regardless, the email is more of a notification and shouldn't
// stop the storage of the data in the db
if (((form as IEncryptedForm)?.emails || []).length > 0) {
void MailService.sendSubmissionToAdmin({
replyToEmails: EmailSubmissionService.extractEmailAnswers(
req.body.responses,
),
form,
submission: {
created: form.created,
id: form._id,
},
attachments: undefined, // Don't send attachments in the email notifications
formData: emailData.formData,
})
}

// Save Responses to Database
let attachmentMetadata = new Map<string, string>()

Expand Down Expand Up @@ -370,6 +335,7 @@ const submitEncryptModeForm = async (
res,
logMeta,
formId,
form,
responses: req.formsg.filteredResponses,
responseMetadata,
submissionContent,
Expand Down Expand Up @@ -628,6 +594,7 @@ const _createSubmission = async ({
submissionContent,
logMeta,
formId,
form,
responseMetadata,
responses,
}: {
Expand All @@ -636,6 +603,7 @@ const _createSubmission = async ({
responseMetadata: EncryptSubmissionDto['responseMetadata']
responses: ParsedClearFormFieldResponse[]
formId: string
form: IPopulatedEncryptedForm
submissionContent: EncryptSubmissionContent
logMeta: CustomLoggerParams['meta']
}) => {
Expand Down Expand Up @@ -670,6 +638,41 @@ const _createSubmission = async ({
},
})

const createdTime = submission.created || new Date()

const logMetaWithSubmission = {
...logMeta,
submissionId,
responseMetadata,
}

logger.info({
message: 'Sending admin notification mail',
meta: logMetaWithSubmission,
})

const emailData = new SubmissionEmailObj(
responses,
new Set(), // the MyInfo prefixes are already inserted in middleware
form.authType,
)

// We don't await for email submission, as the submission gets saved for encrypt
// submissions regardless, the email is more of a notification and shouldn't
// stop the storage of the data in the db
if (((form as IEncryptedForm)?.emails || []).length > 0) {
void MailService.sendSubmissionToAdmin({
replyToEmails: EmailSubmissionService.extractEmailAnswers(responses),
form,
submission: {
created: createdTime,
id: submission.id,
},
attachments: undefined, // Don't send attachments in the email notifications
formData: emailData.formData,
})
}

// TODO 6395 make responseMetadata mandatory
if (responseMetadata) {
reportSubmissionResponseTime(responseMetadata, {
Expand All @@ -682,7 +685,7 @@ const _createSubmission = async ({
res.json({
message: 'Form submission successful.',
submissionId,
timestamp: (submission.created || new Date()).getTime(),
timestamp: createdTime.getTime(),
})

return await performEncryptPostSubmissionActions(submission, responses)
Expand Down

0 comments on commit 99fa925

Please sign in to comment.