mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
refactor: change modeling of obligatory parameters
This commit is contained in:
@@ -51,9 +51,9 @@ export interface SCRoute {
|
|||||||
method: SCRouteHttpVerbs;
|
method: SCRouteHttpVerbs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of obligatory parameters that have to be set via the requested path
|
* Map of obligatory parameters and their type that have to be set via the requested path
|
||||||
*/
|
*/
|
||||||
obligatoryParameters?: string[];
|
obligatoryParameters?: { [k: string]: string };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the type of the request body
|
* Name of the type of the request body
|
||||||
@@ -84,7 +84,7 @@ export abstract class SCAbstractRoute implements SCRoute {
|
|||||||
'SCErrorResponse',
|
'SCErrorResponse',
|
||||||
];
|
];
|
||||||
method: SCRouteHttpVerbs = 'GET';
|
method: SCRouteHttpVerbs = 'GET';
|
||||||
obligatoryParameters?: string[];
|
obligatoryParameters?: { [k: string]: string };
|
||||||
requestBodyName = 'any';
|
requestBodyName = 'any';
|
||||||
responseBodyName = 'any';
|
responseBodyName = 'any';
|
||||||
statusCodeSuccess = 200;
|
statusCodeSuccess = 200;
|
||||||
@@ -97,8 +97,8 @@ export abstract class SCAbstractRoute implements SCRoute {
|
|||||||
|
|
||||||
let obligatoryParameters: string[] = [];
|
let obligatoryParameters: string[] = [];
|
||||||
|
|
||||||
if (Array.isArray(this.obligatoryParameters)) {
|
if (typeof this.obligatoryParameters === 'object') {
|
||||||
obligatoryParameters = this.obligatoryParameters;
|
obligatoryParameters = Object.keys(this.obligatoryParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(parameters).length > obligatoryParameters.length) {
|
if (Object.keys(parameters).length > obligatoryParameters.length) {
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ export class SCThingUpdateRoute extends SCAbstractRoute {
|
|||||||
'SCValidationErrorResponse',
|
'SCValidationErrorResponse',
|
||||||
];
|
];
|
||||||
this.method = 'PUT';
|
this.method = 'PUT';
|
||||||
this.obligatoryParameters = [
|
this.obligatoryParameters = {
|
||||||
'TYPE',
|
TYPE: 'SCThingTypes',
|
||||||
'UID',
|
UID: 'SCUuid',
|
||||||
];
|
};
|
||||||
this.requestBodyName = 'SCThingUpdateRequest';
|
this.requestBodyName = 'SCThingUpdateRequest';
|
||||||
this.responseBodyName = 'SCThingUpdateResponse';
|
this.responseBodyName = 'SCThingUpdateResponse';
|
||||||
this.statusCodeSuccess = 200;
|
this.statusCodeSuccess = 200;
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ export class SCBulkAddRoute extends SCAbstractRoute {
|
|||||||
'SCValidationErrorResponse',
|
'SCValidationErrorResponse',
|
||||||
];
|
];
|
||||||
this.method = 'POST';
|
this.method = 'POST';
|
||||||
this.obligatoryParameters = ['UID'];
|
this.obligatoryParameters = {
|
||||||
|
UID: 'SCUuid',
|
||||||
|
};
|
||||||
this.requestBodyName = 'SCBulkAddRequest';
|
this.requestBodyName = 'SCBulkAddRequest';
|
||||||
this.responseBodyName = 'SCBulkAddResponse';
|
this.responseBodyName = 'SCBulkAddResponse';
|
||||||
this.statusCodeSuccess = 201;
|
this.statusCodeSuccess = 201;
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ export class SCBulkDoneRoute extends SCAbstractRoute {
|
|||||||
'SCValidationErrorResponse',
|
'SCValidationErrorResponse',
|
||||||
];
|
];
|
||||||
this.method = 'POST';
|
this.method = 'POST';
|
||||||
this.obligatoryParameters = ['UID'];
|
this.obligatoryParameters = {
|
||||||
|
UID: 'SCUuid',
|
||||||
|
};
|
||||||
this.requestBodyName = 'SCBulkDoneRequest';
|
this.requestBodyName = 'SCBulkDoneRequest';
|
||||||
this.responseBodyName = 'SCBulkDoneResponse';
|
this.responseBodyName = 'SCBulkDoneResponse';
|
||||||
this.statusCodeSuccess = 204;
|
this.statusCodeSuccess = 204;
|
||||||
|
|||||||
Reference in New Issue
Block a user