Have GET param 'project' work with [] notation

Otherwise queries like $.ajax('/db/campaign', {data: {project:['name','slug']}})
cause 500 errors.
This commit is contained in:
Scott Erickson 2016-08-08 09:35:42 -07:00
parent 57b7791286
commit c89ee139ed
2 changed files with 15 additions and 7 deletions

View file

@ -51,12 +51,14 @@ module.exports =
getProjectFromReq: (req, options) ->
options = _.extend({}, options)
return null unless req.query.project
projection = {}
if req.query.project is 'true'
projection = {original: 1, name: 1, version: 1, description: 1, slug: 1, kind: 1, created: 1, permissions: 1}
result = {}
project = req.query.project
if project is 'true'
result = {original: 1, name: 1, version: 1, description: 1, slug: 1, kind: 1, created: 1, permissions: 1}
else
for field in req.query.project.split(',')
projection[field] = 1
if _.isString(project)
project = project.split(',')
for field in project
result[field] = 1
return projection
return result

View file

@ -29,6 +29,12 @@ describe 'GET /db/campaign', ->
expect(body.length).toBe(4)
done()
it 'accepts project parameter with [] notation', utils.wrap (done) ->
[res, body] = yield request.getAsync getURL('/db/campaign?project[]=name&project[]=type'), { json: true }
expect(res.statusCode).toBe(200)
expect(res.body[0].slug).toBeUndefined()
done()
describe 'with GET query param type', ->
it 'returns campaigns of that type', utils.wrap (done) ->
[res, body] = yield request.getAsync getURL('/db/campaign?type=course'), { json: true }