Files
formbricks-formbricks/apps/web/lib/responses/questionResponseMapping.ts
Matti Nannt 3d0d633bc8 Fix new Session event not triggered every time a new session is created (#624)
* Fix new Session event not triggered every time a new session is created

* make syncWithBackend method private
2023-07-31 16:40:21 +02:00

21 lines
629 B
TypeScript

import { Question } from "@formbricks/types/questions";
import { TResponse } from "@formbricks/types/v1/responses";
export const getQuestionResponseMapping = (
survey: { questions: Question[] },
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;
};