Skip to content

Commit

Permalink
#53 Saves hope and concerns questions with appointments data
Browse files Browse the repository at this point in the history
  • Loading branch information
dangerdak committed Oct 10, 2017
1 parent 07cab49 commit b88681f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/controllers/appointments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { saveAppointments } = require('../model/form_queries');
const { saveAppointments, saveClosing } = require('../model/form_queries');

exports.get = (req, res) => {
res.render('appointments', {
Expand All @@ -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',
Expand Down
17 changes: 9 additions & 8 deletions src/model/queryGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
2 changes: 1 addition & 1 deletion src/views/appointments.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</li>
<li>
I hope that when I leave I am...
<input type="text" name="leaving" placeholder="Write here please" aria-label='please let us know your wishes for when you leave'>
<input type="text" name="hope" placeholder="Write here please" aria-label='please let us know your wishes for when you leave'>
</li>
</ol>
<button type="submit">OK</button>
Expand Down

0 comments on commit b88681f

Please sign in to comment.