2016-03-30 16:57:19 -04:00
|
|
|
utils = require '../lib/utils'
|
|
|
|
errors = require '../commons/errors'
|
|
|
|
wrap = require 'co-express'
|
|
|
|
Promise = require 'bluebird'
|
|
|
|
database = require '../commons/database'
|
|
|
|
mongoose = require 'mongoose'
|
2016-04-06 13:56:06 -04:00
|
|
|
Campaign = require '../models/Campaign'
|
2016-03-30 16:57:19 -04:00
|
|
|
parse = require '../commons/parse'
|
2016-04-06 13:56:06 -04:00
|
|
|
LevelSession = require '../models/LevelSession'
|
2016-03-30 16:57:19 -04:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
fetchByType: wrap (req, res, next) ->
|
|
|
|
type = req.query.type
|
|
|
|
return next() unless type
|
|
|
|
unless _.contains(Campaign.jsonSchema.properties.type.enum, type)
|
|
|
|
throw new errors.UnprocessableEntity('Bad campaign type')
|
|
|
|
dbq = Campaign.find { type: type }
|
|
|
|
dbq.select(parse.getProjectFromReq(req))
|
|
|
|
campaigns = yield dbq.exec()
|
|
|
|
campaigns = (campaign.toObject({req: req}) for campaign in campaigns)
|
|
|
|
res.status(200).send(campaigns)
|