Added resimulateAllSessions route

This commit is contained in:
Michael Schmatz 2014-03-22 09:05:53 -07:00
parent 808cf9280b
commit 9e535e19c6

View file

@ -54,6 +54,29 @@ addPairwiseTaskToQueue = (taskPair, cb) ->
sendEachTaskPairToTheQueue taskPairs, (taskPairError) ->
if taskPairError? then return cb taskPairError,false
cb null, true
module.exports.resimulateAllSessions = (req, res) ->
unless isUserAdmin req then return errors.unauthorized res, "Unauthorized. Even if you are authorized, you shouldn't do this"
originalLevelID = req.body.originalLevelID
levelMajorVersion = parseInt(req.body.levelMajorVersion)
findParameters =
submitted: true
level:
original: originalLevelID
majorVersion: levelMajorVersion
query = LevelSession
.find(findParameters)
.lean()
query.exec (err, result) ->
if err? then return errors.serverError res, err
result = _.sample result, 10
async.each result, resimulateSession.bind(@,originalLevelID,levelMajorVersion), (err) ->
if err? then return errors.serverError res, err
sendResponseObject req, res, {"message":"All task pairs were succesfully sent to the queue"}
module.exports.createNewTask = (req, res) ->