diff options
| author | Adam Soltys <[email protected]> | 2014-08-24 21:46:41 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2014-08-24 21:46:41 -0700 |
| commit | aaadb000fd4dc2fb9758ba92d1ea3d15871c096f (patch) | |
| tree | ce8074d2e0933f88003196c1a83a9ab9b8db6710 /src/routes | |
| parent | affe228986f76b06aa96b3789852a01f8a950644 (diff) | |
| download | coinos-server-aaadb000fd4dc2fb9758ba92d1ea3d15871c096f.tar.gz coinos-server-aaadb000fd4dc2fb9758ba92d1ea3d15871c096f.zip | |
Transaction notes and delete function
Diffstat (limited to 'src/routes')
| -rw-r--r-- | src/routes/transactions.coffee | 43 | ||||
| -rw-r--r-- | src/routes/users.coffee | 2 |
2 files changed, 25 insertions, 20 deletions
diff --git a/src/routes/transactions.coffee b/src/routes/transactions.coffee index 06636a15..8163748a 100644 --- a/src/routes/transactions.coffee +++ b/src/routes/transactions.coffee @@ -1,11 +1,25 @@ db = require('../redis') module.exports = + index: (req, res) -> + res.render('transactions/index', + user: req.params.user, + layout: 'layout', + navigation: true, + js: (-> global.js), + css: (-> global.css) + ) + json: (req, res) -> user = req.params.user r = 'transactions': [] db.lrange("#{user}:transactions", 0, -1, (err, transactions) -> + txid = -> + x = transactions[i++] + return x if typeof x != "number" + return user + ":transactions:" + x + cb = (err, t) -> r.transactions.push t @@ -13,19 +27,10 @@ module.exports = res.write(JSON.stringify(r)) res.end() else - txid = transactions[i++] - if parseInt(txid) - txid = user + ":transactions:" + txid - - db.hgetall(txid, cb) + db.hgetall(txid(), cb) i = 0 - - txid = transactions[i++] - if parseInt(txid) - txid = user + ":transactions:" + txid - - db.hgetall(txid, cb) + db.hgetall(txid(), cb) ) create: (req, res) -> @@ -48,12 +53,14 @@ module.exports = ) ) - index: (req, res) -> - res.render('transactions/index', - user: req.params.user, - layout: 'layout', - navigation: true, - js: (-> global.js), - css: (-> global.css) + update: (req, res) -> + db.hset(req.params.txid, 'notes', req.body.notes, -> + res.end() ) + delete: (req, res) -> + db.del(req.params.txid, -> + db.lrem(req.params.user + ":transactions", 0, req.params.txid, -> + res.end() + ) + ) diff --git a/src/routes/users.coffee b/src/routes/users.coffee index a213f678..0af8a097 100644 --- a/src/routes/users.coffee +++ b/src/routes/users.coffee @@ -81,8 +81,6 @@ module.exports = (sessions) -> ) update: (req, res) -> - return unless req.params.user is req.user.username or - req.user.username is 'admin' if req.body.password is '' delete req.body.password db.hmset("user:"+req.params.user, req.body, -> |
