// Generated by CoffeeScript 1.4.0 var scoring, _; scoring = require('../app/scoring'); _ = require('underscore'); module.exports = function(expressApp, root, derby) { var deprecatedMessage, staticPages; staticPages = derby.createStatic(root); expressApp.get('/privacy', function(req, res) { return staticPages.render('privacy', res); }); expressApp.get('/terms', function(req, res) { return staticPages.render('terms', res); }); deprecatedMessage = 'This REST resource is no longer supported, use /users/:uid/tasks/:taskId/:direction instead.'; expressApp.get('/:uid/up/:score?', function(req, res) { return res.send(200, deprecatedMessage); }); expressApp.get('/:uid/down/:score?', function(req, res) { return res.send(200, deprecatedMessage); }); expressApp.post('/users/:uid/tasks/:taskId/:direction', function(req, res) { var direction, icon, model, service, taskId, title, uid, _ref, _ref1; _ref = req.params, uid = _ref.uid, taskId = _ref.taskId, direction = _ref.direction; _ref1 = req.body, title = _ref1.title, service = _ref1.service, icon = _ref1.icon; console.log({ params: req.params, body: req.body }); if (direction !== 'up' && direction !== 'down') { return res.send(500, ":direction must be 'up' or 'down'"); } model = req.getModel(); model.session.userId = uid; return model.fetch("users." + uid, function(err, user) { var delta, result; if (err || _.isEmpty(user.get())) { err || (err = 'No user with that ID'); return res.send(500, err); } model.ref('_user', user); if (!model.get("_user.tasks." + taskId)) { model.refList("_habitList", "_user.tasks", "_user.habitIds"); model.at('_habitList').push({ id: taskId, type: 'habit', text: (title || taskId) + ' *', value: 0, up: true, down: true, notes: "This task was created by a third-party service. Feel free to edit, it won't harm the connection to that service. Additionally, multiple services may piggy-back off this task." }); } scoring.setModel(model); delta = scoring.score(taskId, direction); result = model.get('_user.stats'); result.delta = delta; return res.send(result); }); }); expressApp.post('/', function(req) { return require('../app/reroll').stripeResponse(req); }); return expressApp.all('*', function(req) { throw "404: " + req.url; }); };