Added CS getById schema validation
ADD
src/assets/server/rest/v1/schemas/chargingstation/chargingstation-get.json
+{
+ "title": "Get one Charging Station",
+ "type": "object",
+ "properties": {
+ "id": {
+ "$ref": "common.json#/definitions/id"
+ },
+ "ProjectFields": {
+ "$ref": "common.json#/definitions/projectFields"
+ }
+ },
+ "required": [
+ "id"
+ ]
+}

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -818,8 +818,8 @@ export default class ChargingStationService {
public static async handleGetChargingStation(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = ChargingStationSecurity.filterChargingStationRequest(req.query);
- UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleGetChargingStation', req.user);
+ const filteredRequest = ChargingStationValidator.getInstance().validateChargingStationGetReq(req.query);
+ UtilsService.assertIdIsProvided(action, filteredRequest.id, MODULE_NAME, 'handleGetChargingStation', req.user);
// Check auth
if (!Authorizations.canReadChargingStation(req.user)) {
throw new AppAuthError({
@@ -827,7 +827,7 @@ export default class ChargingStationService {
user: req.user,
action: Action.READ, entity: Entity.CHARGING_STATION,
module: MODULE_NAME, method: 'handleGetChargingStation',
- value: filteredRequest.ID
+ value: filteredRequest.id
});
}
let projectFields = [
@@ -844,15 +844,15 @@ export default class ChargingStationService {
}
// Query charging station
const chargingStation = await ChargingStationStorage.getChargingStation(
- req.user.tenantID, filteredRequest.ID, {}, projectFields);
- UtilsService.assertObjectExists(action, chargingStation, `Charging Station '${filteredRequest.ID}' does not exist`,
+ req.user.tenantID, filteredRequest.id, {}, projectFields);
+ UtilsService.assertObjectExists(action, chargingStation, `Charging Station '${filteredRequest.id}' does not exist`,
MODULE_NAME, 'handleGetChargingStation', req.user);
// Deleted?
if (chargingStation.deleted) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.OBJECT_DOES_NOT_EXIST_ERROR,
- message: `ChargingStation with ID '${filteredRequest.ID}' is logically deleted`,
+ message: `ChargingStation with ID '${filteredRequest.id}' is logically deleted`,
module: MODULE_NAME,
method: 'handleGetChargingStation',
user: req.user

MODIFY
src/server/rest/v1/validator/ChargingStationValidator.ts
src/server/rest/v1/validator/ChargingStationValidator.ts
+import HttpByIDRequest, { HttpRestByIDRequest } from '../../../../types/requests/HttpByIDRequest';
+
import { HttpChargingStationsRequest } from '../../../../types/requests/HttpChargingStationRequest';
import Schema from './Schema';
import SchemaValidator from './SchemaValidator';
@@ -7,11 +9,13 @@ import global from '../../../../types/GlobalType';
export default class ChargingStationValidator extends SchemaValidator {
private static instance: ChargingStationValidator | undefined;
private chargingStationsGet: Schema;
+ private chargingStationGet: Schema;
private constructor() {
super('ChargingStationValidator');
this.chargingStationsGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstations-get.json`, 'utf8'));
+ this.chargingStationGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-get.json`, 'utf8'));
}
public static getInstance(): ChargingStationValidator {
@@ -27,4 +31,11 @@ export default class ChargingStationValidator extends SchemaValidator {
// Validate deps between components
return data;
}
+
+ public validateChargingStationGetReq(data: any): HttpRestByIDRequest {
+ // Validate schema
+ this.validate(this.chargingStationGet, data);
+ // Validate deps between components
+ return data;
+ }
}

MODIFY
src/types/requests/HttpByIDRequest.ts
src/types/requests/HttpByIDRequest.ts
@@ -3,3 +3,7 @@ import { HttpDatabaseProjectRequest } from './HttpDatabaseRequest';
export default interface HttpByIDRequest extends HttpDatabaseProjectRequest {
ID: string;
}
+
+export interface HttpRestByIDRequest extends HttpDatabaseProjectRequest {
+ id: string;
+}

Added CS getById schema validation