diff options
| author | Adam Soltys <[email protected]> | 2014-07-31 21:06:23 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2014-07-31 21:06:23 -0700 |
| commit | 7c5dfc8d51efe4df4e67f86f33c489a320fcb8f9 (patch) | |
| tree | f387c3d4e3ce9ed0c464659a787b99d8c6e90fb9 /src/routes/transactions.coffee | |
| parent | de1cdd2e3f9d9f36ce3d8e97335341cc3237e829 (diff) | |
| download | coinos-server-7c5dfc8d51efe4df4e67f86f33c489a320fcb8f9.tar.gz coinos-server-7c5dfc8d51efe4df4e67f86f33c489a320fcb8f9.zip | |
Move coffee files to src/ folder
Diffstat (limited to 'src/routes/transactions.coffee')
| -rw-r--r-- | src/routes/transactions.coffee | 38 |
1 files changed, 38 insertions, 0 deletions
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' + ) + |
