From 7c5dfc8d51efe4df4e67f86f33c489a320fcb8f9 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 31 Jul 2014 21:06:23 -0700 Subject: Move coffee files to src/ folder --- src/routes/transactions.coffee | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/routes/transactions.coffee (limited to 'src/routes/transactions.coffee') diff --git a/src/routes/transactions.coffee b/src/routes/transactions.coffee new file mode 100644 index 00000000..0bdaeed6 --- /dev/null +++ b/src/routes/transactions.coffee @@ -0,0 +1,38 @@ +db = require('../redis') + +module.exports = + json: (req, res) -> + user = req.params.user + r = 'transactions': [] + + db.lrange("#{user}:transactions", 0, -1, (err, transactions) -> + process = (err, t) -> + r.transactions.push t + + if i >= transactions.length + res.write(JSON.stringify(r)) + res.end() + else + db.hgetall("#{user}:transactions:#{transactions[i++]}", process) + + i = 0 + db.hgetall("#{user}:transactions:#{transactions[i++]}", process) + ) + + create: (req, res) -> + user = req.params.user + db.incr('transactions', (err, id) -> + db.hmset("#{user}:transactions:#{id}", req.body, -> + db.rpush("#{user}:transactions", id, -> + res.write(JSON.stringify(req.body)) + res.end() + ) + ) + ) + + index: (req, res) -> + res.render('transactions/index', + user: req.params.user, + layout: 'layout' + ) + -- cgit v1.2.3