coderabbit feedback

This commit is contained in:
pandeymangg
2025-11-26 13:39:15 +05:30
parent b9c647ef62
commit 9d77b808d0
3 changed files with 17 additions and 32 deletions

View File

@@ -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: [],
}),
};
}

View File

@@ -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[];
};

View File

@@ -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);