mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-25 16:47:58 -05:00
23 lines
891 B
CoffeeScript
23 lines
891 B
CoffeeScript
|
LevelSession = require('../models/LevelSession')
|
||
|
Handler = require('./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()
|