diff --git a/src/controllers/appointments.js b/src/controllers/appointments.js index 8143e4c..138facd 100644 --- a/src/controllers/appointments.js +++ b/src/controllers/appointments.js @@ -1,4 +1,4 @@ -const { saveAppointments } = require('../model/form_queries'); +const { saveAppointments, saveClosing } = require('../model/form_queries'); exports.get = (req, res) => { res.render('appointments', { @@ -9,6 +9,8 @@ exports.get = (req, res) => { exports.post = (req, res) => { saveAppointments(req.session.id, req.body).then(() => { + return saveClosing(req.session.id, req.body); + }).then(() => { res.render('symptoms', { activePage: { symptoms: true }, pageTitle: 'Symptoms & Difficulties', diff --git a/src/model/queryGenerator.js b/src/model/queryGenerator.js index 35f149b..67c9a1f 100644 --- a/src/model/queryGenerator.js +++ b/src/model/queryGenerator.js @@ -8,19 +8,20 @@ const insertGenerator = (sectionName) => { appointments: ['user_id', 'worker_preferences', 'appointment_preferences', 'parent_involved', 'email', 'mobile', 'telephone', 'contact_preference'], + closing: ['user_id', 'concerns', 'hope'], }; - const dollars = sections[sectionName].map( (item, index) => { - return '$'+(index+1); + const dollars = sections[sectionName].map((item, index) => { + return '$' + (index + 1); }); - const query = 'INSERT INTO ' + sectionName + ' (' + sections[sectionName].join(', ')+') VALUES ('+ - dollars.join(', ') + ') ON CONFLICT (user_id) DO UPDATE SET ('+ - sections[sectionName].slice(1).join(', ')+') = ('+ dollars.slice(1).join(', ')+')'; - return query; + const query = 'INSERT INTO ' + sectionName + ' (' + sections[sectionName].join(', ') + ') VALUES (' + + dollars.join(', ') + ') ON CONFLICT (user_id) DO UPDATE SET (' + + sections[sectionName].slice(1).join(', ') + ') = (' + dollars.slice(1).join(', ') + ')'; + return query; }; const getGenerator = (sectionName) => { - return 'SELECT * FROM '+ sectionName +' WHERE user_id = $1'; -} + return 'SELECT * FROM ' + sectionName + ' WHERE user_id = $1'; +}; module.exports = { insertGenerator, getGenerator }; diff --git a/src/views/appointments.hbs b/src/views/appointments.hbs index d68ca7f..72b5b66 100644 --- a/src/views/appointments.hbs +++ b/src/views/appointments.hbs @@ -39,7 +39,7 @@
  • I hope that when I leave I am... - +