var CrudConfig, ScoresConfig, _, actions, allStudents, extendConfig, makeSimpleStore, ref, ref1, store;
ref = require('./helpers'), CrudConfig = ref.CrudConfig, makeSimpleStore = ref.makeSimpleStore, extendConfig = ref.extendConfig;
_ = require('underscore');
allStudents = function(scores) {
return _.chain(scores).pluck('students').flatten(true).value();
};
ScoresConfig = {
exports: {
getStudent: function(courseId, roleId) {
var students;
students = allStudents(this._get(courseId));
return _.findWhere(allStudents(this._get(courseId)), {
role: parseInt(roleId)
});
},
getAllStudents: function(courseId) {
return allStudents(this._get(courseId));
},
getStudentOfTask: function(courseId, taskId) {
var students;
students = allStudents(this._get(courseId));
taskId = parseInt(taskId);
return _.find(students, function(student) {
var taskIds;
taskIds = _.pluck(student.data, 'id');
return _.indexOf(taskIds, taskId) > -1;
});
}
}
};
extendConfig(ScoresConfig, new CrudConfig());
ref1 = makeSimpleStore(ScoresConfig), actions = ref1.actions, store = ref1.store;
module.exports = {
ScoresActions: actions,
ScoresStore: store
};
|