Files
ember-cli-dunlop/tests/dummy/mirage/config.coffee
T
2018-11-28 14:29:04 -03:00

44 lines
1.5 KiB
CoffeeScript

config = ->
@get '/dunlop/user_filters', (schema, request) ->
#q = {}
#for key, value of request.queryParams
# continue unless match = key.match /^q\[(\w+)\]$/
# q[match[1]] = value
#switch q.f_eq
# when 4 then schema.dunlopUserFilters.all()
# else schema.loadFixtures('dunlop-user-filters')
result = schema.dunlopUserFilters.all()
if filter = request.queryParams.scope_key_matches
match = new RegExp(filter.replace(/%$/, '.*$'))
result = result.filter (model) ->
model.scope_key.match match
result
@post '/dunlop/user_filters', (schema, request) ->
attributes = JSON.parse(request.requestBody)['dunlop/user_filter']
schema.dunlopUserFilters.create(attributes)
# These comments are here to help you get started. Feel free to delete them.
###
Config (with defaults).
Note: these only affect routes defined *after* them!
###
# this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server
# this.namespace = ''; // make this `/api`, for example, if your API is namespaced
# this.timing = 400; // delay for each request, automatically set to 0 during testing
###
Shorthand cheatsheet:
this.get('/posts');
this.post('/posts');
this.get('/posts/:id');
this.put('/posts/:id'); // or this.patch
this.del('/posts/:id');
http://www.ember-cli-mirage.com/docs/v0.3.x/shorthands/
###
export default config