codecombat/server/levels/sessions/level_session_handler.coffee
Sébastien Moratinos 729cd300b7 server reorganize files and folder by features
- move and rename files
- use associative arrays which store handlers for 'dynamically'
  load module from de db route
- store models_path in test/server/common,
  a global model variable has the same name that the filename of the model
2014-01-23 01:01:40 +01:00

22 lines
895 B
CoffeeScript

LevelSession = require('./LevelSession')
Handler = require('../../commons/Handler')
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']
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)
module.exports = new LevelSessionHandler()