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

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -695,7 +695,7 @@ export default class ChargingStationService {
public static async handleDeleteChargingStation(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const chargingStationID = ChargingStationSecurity.filterChargingStationRequestByID(req.query);
+ const chargingStationID = ChargingStationValidator.getInstance().validateChargingStationDeleteReq(req.query).id;
// Check Mandatory fields
UtilsService.assertIdIsProvided(action, chargingStationID, MODULE_NAME,
'handleDeleteChargingStation', req.user);

MODIFY
src/server/rest/v1/validator/ChargingStationValidator.ts
src/server/rest/v1/validator/ChargingStationValidator.ts
@@ -10,12 +10,14 @@ export default class ChargingStationValidator extends SchemaValidator {
private static instance: ChargingStationValidator | undefined;
private chargingStationsGet: Schema;
private chargingStationGet: Schema;
+ private chargingStationDelete: 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'));
+ this.chargingStationDelete = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-delete.json`, 'utf8'));
}
public static getInstance(): ChargingStationValidator {
@@ -28,14 +30,18 @@ export default class ChargingStationValidator extends SchemaValidator {
public validateChargingStationsGetReq(data: any): HttpChargingStationsRequest {
// Validate schema
this.validate(this.chargingStationsGet, data);
- // Validate deps between components
return data;
}
public validateChargingStationGetReq(data: any): HttpRestByIDRequest {
// Validate schema
this.validate(this.chargingStationGet, data);
- // Validate deps between components
+ return data;
+ }
+
+ public validateChargingStationDeleteReq(data: any): HttpRestByIDRequest {
+ // Validate schema
+ this.validate(this.chargingStationDelete, data);
return data;
}
}

Added CS delete schema validation