refactor: use constructor for checking error type in SCRoute

change SCRouteHttpVerbs from type to enum
This commit is contained in:
Wieland Schöbl
2019-02-13 16:20:31 +01:00
parent f9c357fccf
commit e2ff4f4ec6
10 changed files with 152 additions and 74 deletions

View File

@@ -15,6 +15,7 @@
/**
* Possible HTTP verbs for routes
*/
import {SCErrorResponse} from './protocol/errors/ErrorResponse';
import {SCBookAvailabilityRequest} from './protocol/routes/bookAvailability/BookAvailabilityRequest';
import {SCBookAvailabilityResponse} from './protocol/routes/bookAvailability/BookAvailabilityResponse';
import {SCBulkRequest} from './protocol/routes/bulk/BulkRequest';
@@ -35,7 +36,19 @@ import {SCThingUpdateRequest} from './protocol/routes/TYPE/UID/ThingUpdateReques
import {SCThingUpdateResponse} from './protocol/routes/TYPE/UID/ThingUpdateResponse';
import {SCMap} from './types/Map';
export type SCRouteHttpVerbs = 'GET' | 'POST' | 'PUT';
/**
* Possible Verbs for HTTP requests
*/
export enum SCRouteHttpVerbs {
GET = 'GET',
POST = 'POST',
PUT = 'PUT',
}
/**
* The constructor of an error response
*/
export type SCErrorResponseConstructor = new (...args: any) => SCErrorResponse;
/**
* A description of a route
@@ -44,7 +57,7 @@ export interface SCRoute {
/**
* A map of names of possible errors that can be returned by the route with their appropriate status codes
*/
errorNames: string[];
errorNames: SCErrorResponseConstructor[];
/**
* HTTP verb to use to request the route
@@ -81,10 +94,8 @@ export interface SCRoute {
* An abstract route
*/
export abstract class SCAbstractRoute implements SCRoute {
errorNames = [
'SCErrorResponse',
];
method: SCRouteHttpVerbs = 'GET';
errorNames: SCErrorResponseConstructor[] = [];
method: SCRouteHttpVerbs = SCRouteHttpVerbs.GET;
obligatoryParameters?: SCMap<string>;
requestBodyName = 'any';
responseBodyName = 'any';