codecombat/server/levels/sessions/level_session_handler.coffee

27 lines
1 KiB
CoffeeScript
Raw Normal View History

LevelSession = require('./LevelSession')
Handler = require('../../commons/Handler')
2014-01-03 13:32:13 -05:00
TIMEOUT = 1000 * 30 # no activity for 30 seconds means it's not active
class LevelSessionHandler extends Handler
modelClass: LevelSession
editableProperties: ['multiplayer', 'players', 'code', 'completed', 'state',
'levelName', 'creatorName', 'levelID', 'screenshot',
'chat', 'teamSpells','submitted']
2014-01-03 13:32:13 -05:00
getByRelationship: (req, res, args...) ->
return @sendNotFoundError(res) unless args.length is 2 and args[1] is 'active'
start = new Date()
start = new Date(start.getTime() - TIMEOUT)
query = @modelClass.find({'changed': {$gt: start}})
query.exec (err, documents) =>
return @sendDatabaseError(res, err) if err
documents = (@formatEntity(req, doc) for doc in documents)
@sendSuccess(res, documents)
hasAccessToDocument: (req, document, method=null) ->
return true if req.method is 'GET' and document.get('totalScore')
super(arguments...)
2014-01-03 13:32:13 -05:00
module.exports = new LevelSessionHandler()