| 16 | import { IDinoController } from '../interfaces'; |
| 17 | |
| 18 | export class DinoController implements IDinoController { |
| 19 | |
| 20 | private controller: ApiController; |
| 21 | private controllerAction: ControllerAction; |
| 22 | |
| 23 | constructor(controller: ApiController, |
| 24 | controllerAction: ControllerAction) { |
| 25 | this.controller = controller; |
| 26 | this.controllerAction = controllerAction; |
| 27 | } |
| 28 | |
| 29 | // made public for unit-test, not available on contract |
| 30 | // gets query string object and maps the value with corresponding key |
| 31 | // for (@QueryParam() id) returns { id: 45 } |
| 32 | getQueryParams(): any { |
| 33 | let queryParams = |
| 34 | this.controllerAction |
| 35 | .actionAttributes |
| 36 | .actionArguments |
| 37 | .map(x => x.isQueryParam ? x.key : null) |
| 38 | .filter(x => !DataUtility.isNull(x)); |
| 39 | |
| 40 | let queryString = {}; |
| 41 | |
| 42 | for (const queryParam of queryParams) { |
| 43 | // create new object, key = value |
| 44 | queryString[queryParam] = |
| 45 | this.controller.request.query[queryParam]; |
| 46 | } |
| 47 | |
| 48 | return queryString; |
| 49 | } |
| 50 | |
| 51 | // made public for unit-test, not available on contract |
| 52 | // maps url-segments and query-strings |
| 53 | mapSegments( |
| 54 | params: string[], |
| 55 | requestUrl: string): IKeyValuePair[] { |
| 56 | return RouteUtility.mapSegmentsAndQueryToActionArguments(requestUrl, |
| 57 | this.controller.request.path, this.getQueryParams(), params); |
| 58 | } |
| 59 | |
| 60 | // made public for unit-test, not available on contract |
| 61 | // invokes handlers for segments and query params |
| 62 | raiseActionParamsHandlers(values: IKeyValuePair[]): void { |
| 63 | let attr = this.controllerAction.actionAttributes; |
| 64 | |
| 65 | // if request has http-body then ignore first param |
| 66 | // since it is handled by .handleHttpBody() |
| 67 | const parseParams = HttpUtility.hasBody(attr.httpVerb) ? |
| 68 | attr.actionArguments.filter(x => x.paramIndex !== 0) : |
| 69 | attr.actionArguments; |
| 70 | |
| 71 | for (const param of parseParams) { |
| 72 | for (const value of values) { |
| 73 | if (param.key === value.key) { |
| 74 | value.value = param.handler({ |
| 75 | action: param.action, |
nothing calls this directly
no outgoing calls
no test coverage detected