mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-05-04 18:03:45 -04:00
efficient fetching of level sessions
This commit is contained in:
parent
aa4832791e
commit
a1667a0d5e
1 changed files with 3 additions and 3 deletions
|
@ -238,11 +238,11 @@ UserHandler = class UserHandler extends Handler
|
||||||
getLevelSessions: (req, res, userID) ->
|
getLevelSessions: (req, res, userID) ->
|
||||||
query = creator: userID
|
query = creator: userID
|
||||||
isAuthorized = req.user._id+'' is userID or req.user.isAdmin()
|
isAuthorized = req.user._id+'' is userID or req.user.isAdmin()
|
||||||
projection = null
|
projection = {}
|
||||||
if req.query.project
|
if req.query.project
|
||||||
projection = {}
|
|
||||||
projection[field] = 1 for field in req.query.project.split(',') when isAuthorized or not (field in LevelSessionHandler.privateProperties)
|
projection[field] = 1 for field in req.query.project.split(',') when isAuthorized or not (field in LevelSessionHandler.privateProperties)
|
||||||
# If no req.query.project, then LevelSessionHandler.formatEntity will remove private properties if needed.
|
else unless isAuthorized
|
||||||
|
projection[field] = 0 for field in LevelSessionHandler.privateProperties
|
||||||
|
|
||||||
LevelSession.find(query).select(projection).exec (err, documents) =>
|
LevelSession.find(query).select(projection).exec (err, documents) =>
|
||||||
return @sendDatabaseError(res, err) if err
|
return @sendDatabaseError(res, err) if err
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue