Merge pull request #300 from Worklenz/fix/reporting-sidebar-style-fix
refactor(survey-submission): update validation logic and submission d…
This commit is contained in:
@@ -27,10 +27,7 @@ export default function surveySubmissionValidator(req: IWorkLenzRequest, res: IW
|
|||||||
return res.status(200).send(new ServerResponse(false, null, `Answer ${i + 1}: Question ID is required and must be a string`));
|
return res.status(200).send(new ServerResponse(false, null, `Answer ${i + 1}: Question ID is required and must be a string`));
|
||||||
}
|
}
|
||||||
|
|
||||||
// At least one of answer_text or answer_json should be provided
|
// answer_text and answer_json are both optional - users can submit empty answers
|
||||||
if (!answer.answer_text && !answer.answer_json) {
|
|
||||||
return res.status(200).send(new ServerResponse(false, null, `Answer ${i + 1}: Either answer_text or answer_json is required`));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate answer_text if provided
|
// Validate answer_text if provided
|
||||||
if (answer.answer_text && typeof answer.answer_text !== 'string') {
|
if (answer.answer_text && typeof answer.answer_text !== 'string') {
|
||||||
|
|||||||
@@ -96,31 +96,47 @@ export const SurveyPromptModal: React.FC<SurveyPromptModalProps> = ({ forceShow
|
|||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<string, string>);
|
}, {} as Record<string, string>);
|
||||||
|
|
||||||
// Prepare submission data with actual question IDs
|
// Prepare submission data with actual question IDs - only include answered questions
|
||||||
|
const answers: any[] = [];
|
||||||
|
|
||||||
|
if (surveyData.organization_type && questionMap['organization_type']) {
|
||||||
|
answers.push({
|
||||||
|
question_id: questionMap['organization_type'],
|
||||||
|
answer_text: surveyData.organization_type
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (surveyData.user_role && questionMap['user_role']) {
|
||||||
|
answers.push({
|
||||||
|
question_id: questionMap['user_role'],
|
||||||
|
answer_text: surveyData.user_role
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (surveyData.main_use_cases && surveyData.main_use_cases.length > 0 && questionMap['main_use_cases']) {
|
||||||
|
answers.push({
|
||||||
|
question_id: questionMap['main_use_cases'],
|
||||||
|
answer_json: surveyData.main_use_cases
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (surveyData.previous_tools && questionMap['previous_tools']) {
|
||||||
|
answers.push({
|
||||||
|
question_id: questionMap['previous_tools'],
|
||||||
|
answer_text: surveyData.previous_tools
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (surveyData.how_heard_about && questionMap['how_heard_about']) {
|
||||||
|
answers.push({
|
||||||
|
question_id: questionMap['how_heard_about'],
|
||||||
|
answer_text: surveyData.how_heard_about
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const submissionData: ISurveySubmissionRequest = {
|
const submissionData: ISurveySubmissionRequest = {
|
||||||
survey_id: surveyInfo.id,
|
survey_id: surveyInfo.id,
|
||||||
answers: [
|
answers
|
||||||
{
|
|
||||||
question_id: questionMap['organization_type'],
|
|
||||||
answer_text: surveyData.organization_type || ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
question_id: questionMap['user_role'],
|
|
||||||
answer_text: surveyData.user_role || ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
question_id: questionMap['main_use_cases'],
|
|
||||||
answer_json: surveyData.main_use_cases || []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
question_id: questionMap['previous_tools'],
|
|
||||||
answer_text: surveyData.previous_tools || ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
question_id: questionMap['how_heard_about'],
|
|
||||||
answer_text: surveyData.how_heard_about || ''
|
|
||||||
}
|
|
||||||
].filter(answer => answer.question_id) // Filter out any missing question IDs
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await surveyApiService.submitSurveyResponse(submissionData);
|
const response = await surveyApiService.submitSurveyResponse(submissionData);
|
||||||
|
|||||||
Reference in New Issue
Block a user