Files
formbricks/packages/lib/responses.ts
T

21 lines
638 B
TypeScript

import { TResponse } from "@formbricks/types/responses";
import { TSurveyQuestion } from "@formbricks/types/surveys";
export const getQuestionResponseMapping = (
survey: { questions: TSurveyQuestion[] },
response: TResponse
): { question: string; answer: string }[] => {
const questionResponseMapping: { question: string; answer: string }[] = [];
for (const question of survey.questions) {
const answer = response.data[question.id];
questionResponseMapping.push({
question: question.headline,
answer: typeof answer !== "undefined" ? answer.toString() : "",
});
}
return questionResponseMapping;
};