Skip to content

Instantly share code, notes, and snippets.

@nomisum
Created January 26, 2017 20:54
Show Gist options
  • Save nomisum/c2d7813069ef4008d8366279bc121c1c to your computer and use it in GitHub Desktop.
Save nomisum/c2d7813069ef4008d8366279bc121c1c to your computer and use it in GitHub Desktop.
@@ -52,6 +52,21 @@ var getUserAttendance = function (attendance, uid) {
}).pop();
};
var canAttend = function (uid) {
async.parallel([
_.partial(Groups.isMember, uid, 'administrators'),
_.partial(Groups.isMember, uid, 'gastspieler'),
_.partial(Groups.isMember, uid, 'stammspieler'),
_.partial(Groups.isMember, uid, 'anwärter'),
_.partial(Groups.isMember, uid, 'adler')
], function (err, results) {
callback(err, results.indexOf(true) !== -1);
});
};
/*
var getCurrentUser = function (attendance, uid) {
return types.filter(function (type) {
@@ -66,12 +81,26 @@ var _ = require('underscore');
var db = require('../../src/database');
var users = require('../../src/user');
var Groups = require('../../src/groups');
var floatPersistence = require('./lib/persistence-float');
floatPersistence.setDatabase(db);
module.exports = function (params, callback) {
var router = params.router;
router.post('/api/attendance/:tid'), function (req, res, next) {
canAttend(req.uid, function (err, canAttend) {
if (!canAttend) {
return res.status(401).json({});
} else {
next();
}
});
};
router.post('/api/attendance/:tid',
function (req, res, next) {
var type = req.body.type;
@@ -124,11 +153,19 @@ module.exports = function (params, callback) {
var tid = req.params.tid;
var currentUser = req.uid;
/*
if (!currentUser) {
return res.status(401).json({});
}
}*/
// todo: check if guy is in one of permitted groups
async.parallel(
types.map(function (type) { return getAsyncAttendancesGetter(tid, type); }).concat([
function (next) {
floatPersistence.get(tid, next);
@@ -172,13 +209,16 @@ module.exports = function (params, callback) {
res.status(200).json({
myAttendance: getUserAttendance(attendance, currentUser),
attendance: attendance,
attendants: results[types.length]
attendants: results[types.length],
});
});
}
);
});
router.get('/api/attendance/:tid/user/:uid/history', function (req, res, next) {
var tid = req.params.tid;
var uid = req.params.uid;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment