mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Added a getAll handler for achievements
This commit is contained in:
parent
37b47d35de
commit
967e698cb2
3 changed files with 19 additions and 0 deletions
|
@ -0,0 +1,16 @@
|
|||
Achievement = require './Achievement'
|
||||
Handler = require '../commons/Handler'
|
||||
|
||||
class AchievementHandler extends Handler
|
||||
modelClass: Achievement
|
||||
|
||||
jsonSchema = require '../../app/schemas/models/achievement.coffee'
|
||||
|
||||
getAll: (req, res) ->
|
||||
query = @modelClass.find({})
|
||||
query.exec (err, documents) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
documents = (@formatEntity(req, doc) for doc in documents)
|
||||
@sendSuccess(res, documents)
|
||||
|
||||
module.exports = new AchievementHandler()
|
|
@ -9,6 +9,7 @@ module.exports.handlers =
|
|||
'patch': 'patches/patch_handler'
|
||||
'thang_type': 'levels/thangs/thang_type_handler'
|
||||
'user': 'users/user_handler'
|
||||
'achievement': 'achievements/achievement_handler'
|
||||
|
||||
module.exports.routes =
|
||||
[
|
||||
|
|
|
@ -30,6 +30,7 @@ module.exports.setup = (app) ->
|
|||
try
|
||||
moduleName = module.replace '.', '_'
|
||||
name = handlers[moduleName]
|
||||
console.log parts
|
||||
handler = require('../' + name)
|
||||
return handler.getLatestVersion(req, res, parts[1], parts[3]) if parts[2] is 'version'
|
||||
return handler.versions(req, res, parts[1]) if parts[2] is 'versions'
|
||||
|
@ -37,6 +38,7 @@ module.exports.setup = (app) ->
|
|||
return handler.search(req, res) if req.route.method is 'get' and parts[1] is 'search'
|
||||
return handler.getNamesByIDs(req, res) if req.route.method in ['get', 'post'] and parts[1] is 'names'
|
||||
return handler.getByRelationship(req, res, parts[1..]...) if parts.length > 2
|
||||
return handler.getAll(req, res) if req.route.method is 'get' and parts[1] is 'all'
|
||||
return handler.getById(req, res, parts[1]) if req.route.method is 'get' and parts[1]?
|
||||
return handler.patch(req, res, parts[1]) if req.route.method is 'patch' and parts[1]?
|
||||
handler[req.route.method](req, res)
|
||||
|
|
Loading…
Reference in a new issue