Skip to content

Commit

Permalink
fix: xpress pdfs (#952)
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Fernandes <[email protected]>
  • Loading branch information
mutambaraf and simonfernandes authored Feb 20, 2025
1 parent 2bd967b commit 2eb1367
Showing 1 changed file with 47 additions and 11 deletions.
58 changes: 47 additions & 11 deletions apps/backend/src/factory/pdf/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) =>
Expand All @@ -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);
Expand Down Expand Up @@ -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 }) =>
Expand All @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 2eb1367

Please sign in to comment.