Added a getAll handler for achievements

This commit is contained in:
Ruben Vereecken 2014-05-18 15:04:54 +02:00
parent 37b47d35de
commit 967e698cb2
3 changed files with 19 additions and 0 deletions

View file

@ -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()

View file

@ -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 =
[

View file

@ -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)