Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: xpress pdfs #952

Merged
merged 9 commits into from
Feb 20, 2025
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
Loading