Improved routes and put in session access
This commit is contained in:
parent
b174b10642
commit
3ccaa6796a
1 changed files with 16 additions and 17 deletions
|
@ -13,7 +13,7 @@ LevelSession = require '../levels/sessions/LevelSession'
|
||||||
connectToScoringQueue = ->
|
connectToScoringQueue = ->
|
||||||
unless queues.scoringTaskQueue
|
unless queues.scoringTaskQueue
|
||||||
queues.initializeScoringTaskQueue (err, data) ->
|
queues.initializeScoringTaskQueue (err, data) ->
|
||||||
winston.info "Connected to scoring task queue!" unless err?
|
winston.info "Connected to scoring task queue!" unless err?
|
||||||
|
|
||||||
module.exports.setup = (app) ->
|
module.exports.setup = (app) ->
|
||||||
connectToScoringQueue()
|
connectToScoringQueue()
|
||||||
|
@ -24,13 +24,14 @@ module.exports.setup = (app) ->
|
||||||
if message.isEmpty()
|
if message.isEmpty()
|
||||||
sendResponseObject req, res, {"error":"No messages were received."}
|
sendResponseObject req, res, {"error":"No messages were received."}
|
||||||
else
|
else
|
||||||
constructTaskObject message.getBody(), (taskConstructionError, taskObject) ->
|
messageBody = JSON.parse message.getBody()
|
||||||
|
constructTaskObject messageBody, (taskConstructionError, taskObject) ->
|
||||||
if taskConstructionError?
|
if taskConstructionError?
|
||||||
sendResponseObject req, res, {"error":taskConstructionError}
|
sendResponseObject req, res, {"error":taskConstructionError}
|
||||||
else
|
else
|
||||||
sendResponseObject req, res, taskObject
|
sendResponseObject req, res, taskObject
|
||||||
|
|
||||||
|
|
||||||
app.post '/scoring/queue', (req, res) ->
|
app.post '/scoring/queue', (req, res) ->
|
||||||
clientResponseObject = req.body
|
clientResponseObject = req.body
|
||||||
###
|
###
|
||||||
|
@ -44,9 +45,6 @@ module.exports.setup = (app) ->
|
||||||
{"ID":"51eb2714fa058cb20d00fedg", "team":"ogres","metrics": {"reachedGoal":true, "rank":1}}
|
{"ID":"51eb2714fa058cb20d00fedg", "team":"ogres","metrics": {"reachedGoal":true, "rank":1}}
|
||||||
]
|
]
|
||||||
###
|
###
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
res.end("You posted an object to score!")
|
res.end("You posted an object to score!")
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,26 +66,27 @@ constructTaskObject = (taskMessageBody, callback) ->
|
||||||
"taskGeneratingPlayerID": sessionInformation.creator
|
"taskGeneratingPlayerID": sessionInformation.creator
|
||||||
"code": sessionInformation.code
|
"code": sessionInformation.code
|
||||||
"players": sessionInformation.players
|
"players": sessionInformation.players
|
||||||
|
|
||||||
callback err, taskObject
|
callback err, taskObject
|
||||||
|
###
|
||||||
###
|
"players" : [
|
||||||
"players" : [
|
{"ID":"51eb2714fa058cb20d0006ef", "team":"humans", "userCodeMap": "code goes here"}
|
||||||
{"ID":"51eb2714fa058cb20d0006ef", "team":"humans", "userCodeMap": "code goes here"}
|
{"ID":"51eb2714fa058cb20d00fedg", "team":"ogres","userCodeMap": "code goes here"}
|
||||||
{"ID":"51eb2714fa058cb20d00fedg", "team":"ogres","userCodeMap": "code goes here"}
|
]
|
||||||
]
|
###
|
||||||
###
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
getSessionInformation = (sessionID, callback) ->
|
getSessionInformation = (sessionIDString, callback) ->
|
||||||
LevelSession.findOne {"_id": mongoose.Types.ObjectId(sessionID)}, (err, session) ->
|
LevelSession.findOne {"_id": sessionIDString }, (err, session) ->
|
||||||
if err?
|
if err?
|
||||||
callback err, {"error":"There was an error retrieving the session."}
|
callback err, {"error":"There was an error retrieving the session."}
|
||||||
else
|
else
|
||||||
|
session = session.toJSON()
|
||||||
sessionInformation =
|
sessionInformation =
|
||||||
"sessionID": session._id
|
"sessionID": session._id
|
||||||
"players": session.players
|
"players": _.cloneDeep session.players
|
||||||
"code": session.code
|
"code": _.cloneDeep session.code
|
||||||
"changed": session.changed
|
"changed": session.changed
|
||||||
"creator": session.creator
|
"creator": session.creator
|
||||||
callback err, sessionInformation
|
callback err, sessionInformation
|
||||||
|
|
Reference in a new issue