Files
formbricks/packages/lib/responses.ts
T
Dhruwang Jariwala f70cda6e11 refactor: removes old types (#1288)
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
2023-10-20 12:03:16 +00:00

21 lines
638 B
TypeScript

import { TSurveyQuestion } from "@formbricks/types/surveys";
import { TResponse } from "@formbricks/types/responses";
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;
};