| 1 |
import assert from "../../assert"; |
| 2 |
import BaseShorthandRouteHandler from "./base"; |
| 3 |
import { camelize } from "../../utils/inflector"; |
| 4 |
|
| 5 |
/** |
| 6 |
* @hide |
| 7 |
*/ |
| 8 |
export default class PostShorthandRouteHandler extends BaseShorthandRouteHandler { |
| 9 |
/* |
| 10 |
Push a new model of type *camelizedModelName* to the db. |
| 11 |
|
| 12 |
For example, this will push a 'user': |
| 13 |
this.post('/contacts', 'user'); |
| 14 |
*/ |
| 15 |
|
| 16 |
handleStringShorthand(request, modelClass) { |
| 17 |
let modelName = this.shorthand; |
| 18 |
let camelizedModelName = camelize(modelName); |
| 19 |
assert( |
| 20 |
modelClass, |
| 21 |
`The route handler for ${request.url} is trying to access the ${camelizedModelName} model, but that model doesn't exist.` |
| 22 |
); |
| 23 |
|
| 24 |
let attrs = this._getAttrsForRequest( |
| 25 |
request, |
| 26 |
modelClass.camelizedModelName |
| 27 |
); |
| 28 |
return modelClass.create(attrs); |
| 29 |
} |
| 30 |
} |