mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
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:
parent
57b7791286
commit
c89ee139ed
2 changed files with 15 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
|
|
Loading…
Reference in a new issue