Skip to content

Instantly share code, notes, and snippets.

@ulrikstrid
Last active August 29, 2015 14:06
Show Gist options
  • Save ulrikstrid/0dc5002898f0d06c6813 to your computer and use it in GitHub Desktop.
Save ulrikstrid/0dc5002898f0d06c6813 to your computer and use it in GitHub Desktop.
This route does not seem to match anything
plugin.route({
method: 'POST',
path: '/create/page/section',
config: {
validate: {
payload: schemas.sectionCreateSchema
},
pre: [{ method: models.createSection, assign: 'created'}]
},
handler: function(request, reply) {
reply(request.pre.created);
}
});
function createSection(request, reply) {
var DBquery = 'INSERT INTO section ' +
'(' +
'page_id, ' +
'name, ' +
'description, ' +
'text, ' +
'stamp' +
') ' +
'VALUES ' +
'(' +
'$1::int, ' +
'$2::text, ' +
'$3::text, ' +
'$4::text, ' +
'$5::text' +
')';
var DBqueryVars = [
request.payload.page_id,
request.payload.name,
request.payload.description,
request.payload.text,
'CRTBY;'+request.payload.initials
];
pg.connect(conString, function(err, client, done) {
var trans = new Transaction(client);
trans.on('error', function(err) {
console.log(err);
reply(err);
});
trans.begin();
trans.savepoint('beforeQuery');
trans.query(DBquery, DBqueryVars);
client.query("SELECT TOP 1 * FORM section",
function(err, result) {
if(err) {
console.log(err);
reply(err);
}
done();
reply(result);
});
if(process.env.NODE_ENV == 'test') {
trans.rollback('beforeQuery');
}
trans.release('beforeQuery');
trans.commit();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment