You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* In the below API post method, before this "db.query(surveyQuery, surveyValues, (err, surveyResult) => {" all the logs are executed.
* After no code is executed.
* Survey record is created in the database and stopped.
app.post('/savesurveyform', (req, res) => {
console.log('BE - RES BODY:', req.body);
const { surveyData, questions } = req.body;
if (!surveyData || !Array.isArray(questions)) {
return res.status(400).json({ message: 'Invalid request payload. Survey data or questions missing.' });
}
Node.js Version
v22.12.0
NPM Version
10.9.0
Operating System
Windows 11
Subsystem
querystring
Description
* In the below API post method, before this "db.query(surveyQuery, surveyValues, (err, surveyResult) => {" all the logs are executed.
* After no code is executed.
* Survey record is created in the database and stopped.
app.post('/savesurveyform', (req, res) => {
console.log('BE - RES BODY:', req.body);
const { surveyData, questions } = req.body;
if (!surveyData || !Array.isArray(questions)) {
return res.status(400).json({ message: 'Invalid request payload. Survey data or questions missing.' });
}
console.log('BE - SURVEYDATA:', surveyData);
console.log('BE - QUESTIONSDATA:', questions);
const { name, description, description_at_end, thank_you_message } = surveyData;
const surveyQuery =
INSERT INTO surveys (name, description, description_at_end, thank_you_message) VALUES (?, ?, ?, ?)
;const surveyValues = [name, description || null, description_at_end || null, thank_you_message || null];
console.log('Executing Survey Query:', surveyQuery, 'with Values:', surveyValues);
db.query( surveyQuery, surveyValues, (err, surveyResult) => {
console.log('Survey Insert Result:', surveyResult);
if (err) {
console.error('Error inserting survey:', err);
res.status(500).send({ message: 'Error saving survey.' });
return;
}
const surveyId = surveyResult.insertId;
console.log('CREATED SURVEY ID:', surveyId);
const questionQueries = questions.map(child => {
const questionQuery =
INSERT INTO survey_questions (parent_id, Question_Name, Type, Minimum, Maximum, Min_Value_Word, Max_Value_Word, Choices, Pick_Values_with_Additional_Comments, Collect_Comments, isrequired, Rating_Type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
;const questionValues = [
surveyId ?? null,
child.Question_Name || null,
child.Type || null,
child.Minimum && child.Minimum !== '' ? parseInt(child.Minimum) : null,
child.Maximum && child.Maximum !== '' ? parseInt(child.Maximum) : null,
child.Min_Value_Word || null,
child.Max_Value_Word || null,
child.Choices || null,
child.Pick_Values_with_Additional_Comments || null,
child.Collect_Comments ? 1 : 0,
child.isrequired ? 1 : 0,
child.Rating_Type || null,
];
return new Promise((resolve, reject) => {
db.query(questionQuery, questionValues, (error, result) => {
if (error) return reject(error);
resolve(result);
});
});
});
);
});
Minimal Reproduction
No response
Output
No response
Before You Submit
The text was updated successfully, but these errors were encountered: