codecombat/server/routes/index.js
2016-03-29 14:18:41 -04:00

94 lines
4 KiB
JavaScript

// Generated by CoffeeScript 1.10.0
(function() {
var mw;
mw = require('../middleware');
module.exports.setup = function(app) {
var Article, TrialRequest;
app.post('/auth/login-facebook', mw.auth.loginByFacebook);
app.post('/auth/login-gplus', mw.auth.loginByGPlus);
app.post('/auth/spy', mw.auth.spy);
app.post('/auth/stop-spying', mw.auth.stopSpying);
Article = require('../models/Article');
app.get('/db/article', mw.rest.get(Article));
app.post('/db/article', mw.auth.checkHasPermission(['admin', 'artisan']), mw.rest.post(Article));
app.get('/db/article/names', mw.named.names(Article));
app.post('/db/article/names', mw.named.names(Article));
app.get('/db/article/:handle', mw.rest.getByHandle(Article));
app.put('/db/article/:handle', mw.auth.checkHasPermission(['admin']), mw.rest.put(Article));
app.patch('/db/article/:handle', mw.auth.checkHasPermission(['admin']), mw.rest.put(Article));
app.post('/db/article/:handle/new-version', mw.auth.checkLoggedIn(), mw.versions.postNewVersion(Article, {
hasPermissionsOrTranslations: 'artisan'
}));
app.get('/db/article/:handle/versions', mw.versions.versions(Article));
app.get('/db/article/:handle/version/?(:version)?', mw.versions.getLatestVersion(Article));
app.get('/db/article/:handle/files', mw.files.files(Article, {
module: 'article'
}));
app.get('/db/article/:handle/patches', mw.patchable.patches(Article));
app.post('/db/article/:handle/watchers', mw.patchable.joinWatchers(Article));
app["delete"]('/db/article/:handle/watchers', mw.patchable.leaveWatchers(Article));
app.get('/db/user', mw.users.fetchByGPlusID, mw.users.fetchByFacebookID);
app.get('/db/products', require('./db/product').get);
TrialRequest = require('../models/TrialRequest');
app.get('/db/trial.request', mw.trialRequests.fetchByApplicant, mw.auth.checkHasPermission(['admin']), mw.rest.get(TrialRequest));
app.post('/db/trial.request', mw.auth.checkLoggedIn(), mw.trialRequests.post);
app.get('/db/trial.request/:handle', mw.auth.checkHasPermission(['admin']), mw.rest.getByHandle(TrialRequest));
app.put('/db/trial.request/:handle', mw.auth.checkHasPermission(['admin']), mw.trialRequests.put);
return app.get('/healthcheck', function(req, res) {
var User, async, error, error1;
try {
async = require('async');
User = require('../users/User');
return async.waterfall([
function(callback) {
return User.find({}).limit(1).exec(callback);
}, function(last, callback) {
if (!(callback.length > 0)) {
return "No users found";
}
return User.findOne({
slug: 'healthcheck'
}).exec(callback);
}, function(hcuser, callback) {
var user;
if (hcuser) {
return callback(null, hcuser);
}
user = new User({
anonymous: false,
name: 'healthcheck',
nameLower: 'healthcheck',
slug: 'healthcheck',
email: 'rob+healthcheck@codecombat.com',
emailLower: 'rob+healthcheck@codecombat.com'
});
user.set('testGroupNumber', Math.floor(Math.random() * 256));
return user.save(function(err) {
if (err) {
return callback(err);
}
return callback(null, user);
});
}, function(hcuser, callback) {
var activity;
activity = hcuser.trackActivity('healthcheck', 1);
return hcuser.update({
activity: activity
}, callback);
}
], function(err) {
if (err) {
return res.status(500).send(err.toString());
}
return res.send("OK");
});
} catch (error1) {
error = error1;
return res.status(500).send(error.toString());
}
});
};
}).call(this);