mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-30 18:30:32 -06:00
coderabbit feedback
This commit is contained in:
@@ -51,16 +51,18 @@ export const GET = withV1ApiWrapper({
|
||||
};
|
||||
}
|
||||
|
||||
const hasBlocks = result.survey.blocks && result.survey.blocks.length > 0;
|
||||
if (hasBlocks) {
|
||||
const surveyWithQuestions = {
|
||||
...result.survey,
|
||||
questions: transformBlocksToQuestions(result.survey.blocks, result.survey.endings),
|
||||
blocks: [],
|
||||
};
|
||||
const shouldTransformToQuestions =
|
||||
result.survey.blocks &&
|
||||
result.survey.blocks.length > 0 &&
|
||||
result.survey.blocks.every((block) => block.elements.length === 1);
|
||||
|
||||
if (shouldTransformToQuestions) {
|
||||
return {
|
||||
response: responses.successResponse(surveyWithQuestions),
|
||||
response: responses.successResponse({
|
||||
...result.survey,
|
||||
questions: transformBlocksToQuestions(result.survey.blocks, result.survey.endings),
|
||||
blocks: [],
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -474,23 +474,6 @@ export const transformBlocksToQuestions = (
|
||||
questions.push(element);
|
||||
}
|
||||
|
||||
for (const question of questions) {
|
||||
if (Array.isArray(question.logic) && question.logic.length > 0) {
|
||||
question.logic = question.logic.map(
|
||||
(item: { actions: TSurveyBlockLogicAction[]; [key: string]: unknown }) => {
|
||||
return {
|
||||
...item,
|
||||
actions: reverseLogicActions(item.actions, blockIdToQuestionId, endingIds),
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof question.logicFallback === "string") {
|
||||
question.logicFallback = reverseLogicFallback(question.logicFallback, blockIdToQuestionId, endingIds);
|
||||
}
|
||||
}
|
||||
|
||||
return questions as TSurveyQuestion[];
|
||||
};
|
||||
|
||||
|
||||
@@ -2015,7 +2015,7 @@ const validateConditions = (
|
||||
const { leftOperand, operator, rightOperand } = condition;
|
||||
|
||||
// Validate left operand
|
||||
if (leftOperand.type === "element") {
|
||||
if (leftOperand.type === "question") {
|
||||
const questionId = leftOperand.value;
|
||||
const questionIdx = survey.questions.findIndex((q) => q.id === questionId);
|
||||
const question = questionIdx !== -1 ? survey.questions[questionIdx] : undefined;
|
||||
@@ -2072,7 +2072,7 @@ const validateConditions = (
|
||||
|
||||
if (question.type === TSurveyQuestionTypeEnum.OpenText) {
|
||||
// Validate right operand
|
||||
if (rightOperand?.type === "element") {
|
||||
if (rightOperand?.type === "question") {
|
||||
const quesId = rightOperand.value;
|
||||
const ques = survey.questions.find((q) => q.id === quesId);
|
||||
|
||||
@@ -2304,7 +2304,7 @@ const validateConditions = (
|
||||
});
|
||||
}
|
||||
} else if (question.type === TSurveyQuestionTypeEnum.Date) {
|
||||
if (rightOperand?.type === "element") {
|
||||
if (rightOperand?.type === "question") {
|
||||
const quesId = rightOperand.value;
|
||||
const ques = survey.questions.find((q) => q.id === quesId);
|
||||
|
||||
@@ -2434,7 +2434,7 @@ const validateConditions = (
|
||||
}
|
||||
|
||||
// Validate right operand
|
||||
if (rightOperand?.type === "element") {
|
||||
if (rightOperand?.type === "question") {
|
||||
const questionId = rightOperand.value;
|
||||
const question = survey.questions.find((q) => q.id === questionId);
|
||||
|
||||
@@ -2531,7 +2531,7 @@ const validateConditions = (
|
||||
}
|
||||
|
||||
// Validate right operand
|
||||
if (rightOperand?.type === "element") {
|
||||
if (rightOperand?.type === "question") {
|
||||
const questionId = rightOperand.value;
|
||||
const question = survey.questions.find((q) => q.id === questionId);
|
||||
|
||||
@@ -2654,7 +2654,7 @@ const validateActions = (
|
||||
};
|
||||
}
|
||||
|
||||
if (action.value.type === "element") {
|
||||
if (action.value.type === "question") {
|
||||
const allowedQuestions = [
|
||||
TSurveyQuestionTypeEnum.OpenText,
|
||||
TSurveyQuestionTypeEnum.MultipleChoiceSingle,
|
||||
@@ -2686,7 +2686,7 @@ const validateActions = (
|
||||
};
|
||||
}
|
||||
|
||||
if (action.value.type === "element") {
|
||||
if (action.value.type === "question") {
|
||||
const allowedQuestions = [TSurveyQuestionTypeEnum.Rating, TSurveyQuestionTypeEnum.NPS];
|
||||
|
||||
const selectedQuestion = previousQuestions.find((q) => q.id === action.value.value);
|
||||
|
||||
Reference in New Issue
Block a user