Skip to content

Commit 1bf1b5d

Browse files
committed
fix: make responses data compatible with pdf
1 parent 6f5954d commit 1bf1b5d

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

src/app/modules/submission/email-submission/email-submission.util.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export const getAnswerForSignature = (
259259

260260
/**
261261
* Formats the response for sending to the submitter (autoReplyData),
262-
* the table that is sent to the admin (formData),
262+
* the table that is sent to the admin (responseData),
263263
* and the json used by data collation tool (dataCollationData).
264264
*
265265
* @param response
@@ -292,7 +292,7 @@ export const getFormattedResponse = (
292292
}
293293

294294
// Send all the fields to admin
295-
const formData = {
295+
const responseData = {
296296
question: getFormDataPrefixedQuestion(response, hashedFields),
297297
answerTemplate: answerSplitByNewLine,
298298
answer,
@@ -301,7 +301,7 @@ export const getFormattedResponse = (
301301
return {
302302
autoReplyData,
303303
dataCollationData,
304-
formData,
304+
responseData,
305305
}
306306
}
307307

@@ -462,18 +462,18 @@ export const mapRouteError: MapRouteError = (error) => {
462462

463463
/**
464464
* Concatenate response into a string for hashing
465-
* @param formData Field-value tuples for admin email
465+
* @param responsesData Field-value tuples for admin email
466466
* @param attachments Array of attachments as buffers
467467
* @returns concatenated response to hash
468468
*/
469469
export const concatAttachmentsAndResponses = (
470-
formData: EmailAdminDataField[],
470+
responsesData: EmailAdminDataField[],
471471
attachments: IAttachmentInfo[],
472472
): string => {
473473
let response = ''
474-
response += formData.reduce((acc, fieldData) => {
475-
const question = fieldData.question.toString().trim()
476-
const answer = fieldData.answer.toString().trim()
474+
response += responsesData.reduce((acc, fieldResponseData) => {
475+
const question = fieldResponseData.question.toString().trim()
476+
const answer = fieldResponseData.answer.toString().trim()
477477
return acc + `${question} ${answer}; `
478478
}, '')
479479
response += attachments.reduce((acc, { content }) => acc + content, '')
@@ -698,9 +698,9 @@ export class SubmissionEmailObj {
698698
: unmaskedAutoReplyData
699699
}
700700
/**
701-
* Getter function to return formData which is used to send responses to admin
701+
* Getter function to return responsesData which is used to send responses to admin
702702
*/
703-
get formData(): EmailAdminDataField[] {
703+
get responsesData(): EmailAdminDataField[] {
704704
return this.parsedResponses.flatMap((response) =>
705705
createFormattedDataForOneField(
706706
response,

src/app/modules/submission/encrypt-submission/encrypt-submission.service.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ import {
4848
} from '../submission.errors'
4949
import { sendEmailConfirmations } from '../submission.service'
5050
import { ProcessedFieldResponse } from '../submission.types'
51-
import { extractEmailConfirmationData } from '../submission.utils'
51+
import {
52+
extractEmailConfirmationData
53+
} from '../submission.utils'
5254

5355
import { CHARTS_MAX_SUBMISSION_RESULTS } from './encrypt-submission.constants'
5456
import { SaveEncryptSubmissionParams } from './encrypt-submission.types'
@@ -184,9 +186,7 @@ const generatePdfAttachmentIfRequired = ({
184186
autoReplyMailDatas: AutoReplyMailData[]
185187
submission: IEncryptedSubmissionSchema
186188
form: IPopulatedEncryptedForm
187-
responsesData: (Pick<EmailAdminDataField, 'question' | 'answerTemplate'> & {
188-
answer?: EmailAdminDataField['answer']
189-
})[]
189+
responsesData: EmailAdminDataField[]
190190
}): ResultAsync<Mail.Attachment | undefined, AutoreplyPdfGenerationError> => {
191191
if (
192192
!checkIfPdfGenerationIsRequired({
@@ -197,13 +197,20 @@ const generatePdfAttachmentIfRequired = ({
197197
return okAsync(undefined)
198198
}
199199

200+
const pdfResponsesData = responsesData.map(
201+
({ question, answerTemplate }) => ({
202+
question,
203+
answerTemplate,
204+
}),
205+
)
206+
200207
const renderData: AutoreplySummaryRenderData = {
201208
refNo: submission.id,
202209
formTitle: form.title,
203210
submissionTime: moment(submission.created)
204211
.tz('Asia/Singapore')
205212
.format('ddd, DD MMM YYYY hh:mm:ss A'),
206-
formData: responsesData,
213+
formData: pdfResponsesData,
207214
formUrl: `${config.app.appUrl}/${form._id}`,
208215
}
209216

@@ -281,14 +288,14 @@ export const performEncryptPostSubmissionActions = ({
281288
})
282289
: []
283290

284-
const emailData = new SubmissionEmailObj(
291+
const { responsesData, dataCollationData } = new SubmissionEmailObj(
285292
emailFields,
286293
new Set(), // the MyInfo prefixes are already inserted in middleware
287294
form.authType,
288295
)
289296
// Since we insert the [MyInfo] prefix in `encrypt-submission.middleware.ts`:L434
290297
// we want to remove it for the dataCollationData
291-
const dataCollationData = emailData.dataCollationData.map((item) => ({
298+
const formattedDataCollationData = dataCollationData.map((item) => ({
292299
question: item.question.startsWith(MYINFO_PREFIX)
293300
? item.question.slice(MYINFO_PREFIX.length)
294301
: item.question,
@@ -309,7 +316,7 @@ export const performEncryptPostSubmissionActions = ({
309316
autoReplyMailDatas: recipientEmailDatas,
310317
submission,
311318
form,
312-
responsesData: emailData.formData,
319+
responsesData,
313320
})
314321

315322
return pdfAttachmentResult.andThen((pdfAttachment) => {
@@ -323,8 +330,8 @@ export const performEncryptPostSubmissionActions = ({
323330
id: submission.id,
324331
},
325332
submissionAttachments,
326-
formData: emailData.formData,
327-
dataCollationData,
333+
formData: responsesData,
334+
dataCollationData: formattedDataCollationData,
328335
pdfAttachment: checkIfAdminPdfIsRequired()
329336
? pdfAttachment
330337
: undefined,
@@ -342,7 +349,7 @@ export const performEncryptPostSubmissionActions = ({
342349
submission,
343350
submissionAttachments,
344351
recipientData: recipientEmailDatas,
345-
responsesData: emailData.formData,
352+
responsesData,
346353
pdfAttachment: checkIfRespondentFormSummaryIsRequired({
347354
isPaymentEnabled,
348355
autoReplyMailDatas: recipientEmailDatas,

src/types/email_mode_data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ export type EmailDataFields =
2727
export interface EmailData {
2828
autoReplyData: EmailRespondentConfirmationField[]
2929
dataCollationData: EmailDataCollationToolField[]
30-
formData: EmailAdminDataField[]
30+
responsesData: EmailAdminDataField[]
3131
}
3232

3333
export interface EmailDataForOneField {
3434
autoReplyData?: EmailRespondentConfirmationField
3535
dataCollationData?: EmailDataCollationToolField
36-
formData: EmailAdminDataField
36+
responseData: EmailAdminDataField
3737
}
3838

3939
export interface IAttachmentInfo {

0 commit comments

Comments
 (0)