| 1 |
import BaseRouteHandler from "../base"; |
| 2 |
|
| 3 |
/** |
| 4 |
@hide |
| 5 |
*/ |
| 6 |
export default class BaseShorthandRouteHandler extends BaseRouteHandler { |
| 7 |
constructor(schema, serializerOrRegistry, shorthand, path, options = {}) { |
| 8 |
super(); |
| 9 |
shorthand = shorthand || this.getModelClassFromPath(path); |
| 10 |
this.schema = schema; |
| 11 |
this.serializerOrRegistry = serializerOrRegistry; |
| 12 |
this.shorthand = shorthand; |
| 13 |
this.options = options; |
| 14 |
|
| 15 |
let type = Array.isArray(shorthand) ? "array" : typeof shorthand; |
| 16 |
if (type === "string") { |
| 17 |
let modelClass = this.schema[this.schema.toCollectionName(shorthand)]; |
| 18 |
this.handle = (request) => { |
| 19 |
return this.handleStringShorthand(request, modelClass); |
| 20 |
}; |
| 21 |
} else if (type === "array") { |
| 22 |
let modelClasses = shorthand.map( |
| 23 |
(modelName) => this.schema[this.schema.toCollectionName(modelName)] |
| 24 |
); |
| 25 |
this.handle = (request) => { |
| 26 |
return this.handleArrayShorthand(request, modelClasses); |
| 27 |
}; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
// handleStringShorthand() { |
| 32 |
// |
| 33 |
// } |
| 34 |
// |
| 35 |
// handleArrayShorthand() { |
| 36 |
// |
| 37 |
// } |
| 38 |
} |