mirror of
https://github.com/Matewoo/tablet-web-survey.git
synced 2026-11-18 13:52:47 +01:00
ignore empty results
Pressing submit without selection now ignores this result.
This commit is contained in:
@@ -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,16 +44,19 @@ app.post('/submit', (req, res) => {
|
|||||||
rating: results[category]
|
rating: results[category]
|
||||||
}));
|
}));
|
||||||
|
|
||||||
csvWriter.writeRecords(records)
|
if (records.length > 0) {
|
||||||
.then(() => {
|
csvWriter.writeRecords(records)
|
||||||
console.log('Received feedback:', results);
|
.then(() => {
|
||||||
res.json({ status: 'success' });
|
console.log('Received feedback:', results);
|
||||||
})
|
res.json({ status: 'success' });
|
||||||
.catch(error => {
|
})
|
||||||
console.error('Error writing to CSV:', error);
|
.catch(error => {
|
||||||
res.status(500).json({ status: 'error', message: 'Error writing to CSV' });
|
console.error('Error writing to CSV:', error);
|
||||||
});
|
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) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user