From df2d8b80830f7d1ceb23ff7cd5eee2b8d72ef0fa Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Mon, 20 Jul 2015 15:11:59 +0200 Subject: [PATCH] Commit forgotten file --- posts/coin-id/index.js | 32 ++++++++++++++++++++++++++++++++ posts/coin-id/urls.js | 3 +++ 2 files changed, 35 insertions(+) create mode 100644 posts/coin-id/index.js create mode 100644 posts/coin-id/urls.js diff --git a/posts/coin-id/index.js b/posts/coin-id/index.js new file mode 100644 index 0000000..bf886bc --- /dev/null +++ b/posts/coin-id/index.js @@ -0,0 +1,32 @@ +var pg = require('pg'); +var secret = require('../../private'); +var Log = require('../../lib/NodeLog.js'); + +function insertCoinId(client, release, exp_id, coin_ids) { + + if (coin_ids.length > 0) { + client.query( + 'INSERT INTO Coin(exp_id, coin_id) VALUES ($1, $2);', + [exp_id,coin_ids.shift()], + function(err, result) { + if (err !== null) + Log.dberror(err + ' coin-id'); + + if (coin_ids.length === 0) + release(); + else + insertCoinId(client, release, exp_id, coin_ids); + } + ); + } +} + +module.exports.index = function(req, res) { + + pg.connect(secret.url, function(err, client, release) { + insertCoinId(client, release, req.session.exp_id, req.body.indices); + }); + + res.setHeader('Content-Type', 'text/html'); + res.send(""); +}; diff --git a/posts/coin-id/urls.js b/posts/coin-id/urls.js new file mode 100644 index 0000000..c5a8d7e --- /dev/null +++ b/posts/coin-id/urls.js @@ -0,0 +1,3 @@ +module.exports = { + '/coin-id': 'index' +};