ignore empty results

Pressing submit without selection now ignores this result.
This commit is contained in:
Matewoo
2025-01-13 17:58:09 +01:00
parent e29fb3ddab
commit cbab6312d8
+7 -4
View File
@@ -20,9 +20,9 @@ app.use(bodyParser.json());
const csvWriter = createCsvWriter({ const csvWriter = createCsvWriter({
path: 'survey_results.csv', path: 'survey_results.csv',
header: [ header: [
{id: 'date', title: 'DATE'}, { id: 'date', title: 'DATE' },
{id: 'category', title: 'CATEGORY'}, { id: 'category', title: 'CATEGORY' },
{id: 'rating', title: 'RATING'} { id: 'rating', title: 'RATING' }
], ],
append: true append: true
}); });
@@ -44,6 +44,7 @@ app.post('/submit', (req, res) => {
rating: results[category] rating: results[category]
})); }));
if (records.length > 0) {
csvWriter.writeRecords(records) csvWriter.writeRecords(records)
.then(() => { .then(() => {
console.log('Received feedback:', results); console.log('Received feedback:', results);
@@ -53,7 +54,9 @@ app.post('/submit', (req, res) => {
console.error('Error writing to CSV:', error); console.error('Error writing to CSV:', error);
res.status(500).json({ status: 'error', message: 'Error writing to CSV' }); res.status(500).json({ status: 'error', message: 'Error writing to CSV' });
}); });
}); }
});
// Serve the survey results page // Serve the survey results page
app.get('/survey', (req, res) => { app.get('/survey', (req, res) => {