From 2eb1367aa49b4b1e195b43e358efb1b610968558 Mon Sep 17 00:00:00 2001 From: Farai Mutambara <71100224+mutambaraf@users.noreply.github.com> Date: Thu, 20 Feb 2025 10:53:58 +0000 Subject: [PATCH] fix: xpress pdfs (#952) Co-authored-by: Simon Fernandes --- apps/backend/src/factory/pdf/proposal.ts | 58 +++++++++++++++++++----- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/apps/backend/src/factory/pdf/proposal.ts b/apps/backend/src/factory/pdf/proposal.ts index 9a9bf66af8..894b5a082c 100644 --- a/apps/backend/src/factory/pdf/proposal.ts +++ b/apps/backend/src/factory/pdf/proposal.ts @@ -169,23 +169,31 @@ const addTopicInformation = async ( } const questionaryAttachments: Attachment[] = []; - + const updatedAnswers: Answer[] = []; for (let i = 0; i < answers.length; i++) { const answer = answers[i]; questionaryAttachments.push(...getFileAttachments(answer)); if (answer.question.dataType === DataType.SAMPLE_DECLARATION) { - answer.value = samples + const value = samples .filter((sample) => sample.questionId === answer.question.id) .map((sample) => sample); + updatedAnswers.push({ + ...answer, + value, + }); } else if (answer.question.dataType === DataType.GENERIC_TEMPLATE) { - answer.value = genericTemplates + const value = genericTemplates .filter( (genericTemplate) => genericTemplate.questionId === answer.question.id ) .map((genericTemplate) => genericTemplate); + updatedAnswers.push({ + ...answer, + value, + }); } else if (answer.question.dataType === DataType.INSTRUMENT_PICKER) { const ids = Array.isArray(answer.value) ? answer.value.map((v: { instrumentId: string }) => @@ -203,13 +211,21 @@ const addTopicInformation = async ( const call = await callDataSource.getCallByAnswerIdProposal( answer.answerId ); - answer.value = instrumentPickerAnswer(answer, instruments, call); + const value = instrumentPickerAnswer(answer, instruments, call); + updatedAnswers.push({ + ...answer, + value, + }); + } else { + updatedAnswers.push({ + ...answer, + }); } } updatedProposalPDFData.questionarySteps.push({ ...step, - fields: answers, + fields: updatedAnswers, }); updatedProposalPDFData.attachments.push(...questionaryAttachments); updatedProposalPDFData.attachments.push(...sampleAttachments); @@ -365,23 +381,31 @@ export const collectProposalPDFData = async ( } const questionaryAttachments: Attachment[] = []; - + const updatedAnswers: Answer[] = []; for (let i = 0; i < answers.length; i++) { const answer = answers[i]; questionaryAttachments.push(...getFileAttachments(answer)); if (answer.question.dataType === DataType.SAMPLE_DECLARATION) { - answer.value = samples + const value = samples .filter((sample) => sample.questionId === answer.question.id) .map((sample) => sample); + updatedAnswers.push({ + ...answer, + value, + }); } else if (answer.question.dataType === DataType.GENERIC_TEMPLATE) { - answer.value = genericTemplates + const value = genericTemplates .filter( (genericTemplate) => genericTemplate.questionId === answer.question.id ) .map((genericTemplate) => genericTemplate); + updatedAnswers.push({ + ...answer, + value, + }); } else if (answer.question.dataType === DataType.INSTRUMENT_PICKER) { const ids = Array.isArray(answer.value) ? answer.value.map((v: { instrumentId: string }) => @@ -391,7 +415,11 @@ export const collectProposalPDFData = async ( const instruments = await baseContext.queries.instrument.getInstrumentsByIds(user, ids); - answer.value = instrumentPickerAnswer(answer, instruments, call); + const value = instrumentPickerAnswer(answer, instruments, call); + updatedAnswers.push({ + ...answer, + value, + }); } else if (answer.question.dataType === DataType.TECHNIQUE_PICKER) { const techniqueIds = Array.isArray(answer.value) ? answer.value @@ -401,15 +429,23 @@ export const collectProposalPDFData = async ( user, techniqueIds ); - answer.value = techniques?.length + const value = techniques?.length ? techniques.map((technique) => technique.name).join(', ') : ''; + updatedAnswers.push({ + ...answer, + value, + }); + } else { + updatedAnswers.push({ + ...answer, + }); } } out.questionarySteps.push({ ...step, - fields: answers, + fields: updatedAnswers, }); out.attachments.push(...questionaryAttachments); out.attachments.push(...sampleAttachments);