Added Smartcharging trigger validation
ADD
src/assets/server/rest/v1/schemas/chargingstation/smartcharing-trigger.json
+{
+ "title": "Trigger Smart Charging Request",
+ "type": "object",
+ "properties": {
+ "SiteAreaID": {
+ "$ref": "common.json#/definitions/id"
+ }
+ },
+ "required": [
+ "SiteAreaID"
+ ]
+}

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -521,7 +521,7 @@ export default class ChargingStationService {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.SMART_CHARGING,
Action.UPDATE, Entity.SITE_AREA, MODULE_NAME, 'handleTriggerSmartCharging');
// Filter
- const filteredRequest = ChargingStationSecurity.filterTriggerSmartCharging(req.query);
+ const filteredRequest = ChargingStationValidator.getInstance().validateSmartChargingTriggerReq(req.query);
UtilsService.assertIdIsProvided(action, filteredRequest.SiteAreaID, MODULE_NAME, 'handleTriggerSmartCharging', req.user);
// Get Site Area
const siteArea = await SiteAreaStorage.getSiteArea(req.user.tenantID, filteredRequest.SiteAreaID);

MODIFY
src/server/rest/v1/validator/ChargingStationValidator.ts
src/server/rest/v1/validator/ChargingStationValidator.ts
-import { HttpChargingStationCommandRequest, HttpChargingStationConnectorRequest, HttpChargingStationGetFirmwareRequest, HttpChargingStationOcppRequest, HttpChargingStationRequest, HttpChargingStationsRequest, HttpDownloadQrCodeRequest } from '../../../../types/requests/HttpChargingStationRequest';
+import { HttpChargingStationCommandRequest, HttpChargingStationConnectorRequest, HttpChargingStationGetFirmwareRequest, HttpChargingStationOcppRequest, HttpChargingStationRequest, HttpChargingStationsRequest, HttpDownloadQrCodeRequest, HttpTriggerSmartChargingRequest } from '../../../../types/requests/HttpChargingStationRequest';
import { ChargingProfile } from '../../../../types/ChargingProfile';
import HttpByIDRequest from '../../../../types/requests/HttpByIDRequest';
@@ -18,6 +18,7 @@ export default class ChargingStationValidator extends SchemaValidator {
private chargingStationOcppParametersGet: Schema;
private chargingProfileCreate: Schema;
private chargingStationFirmwareDownload: Schema;
+ private smartChargingTrigger: Schema;
private constructor() {
@@ -31,6 +32,7 @@ export default class ChargingStationValidator extends SchemaValidator {
this.chargingStationOcppParametersGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-ocpp-parameters-get.json`, 'utf8'));
this.chargingProfileCreate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingprofile-create.json`, 'utf8'));
this.chargingStationFirmwareDownload = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-firmware-download.json`, 'utf8'));
+ this.chargingStationFirmwareDownload = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/smartcharging-trigger.json`, 'utf8'));
}
public static getInstance(): ChargingStationValidator {
@@ -93,4 +95,10 @@ export default class ChargingStationValidator extends SchemaValidator {
this.validate(this.chargingStationFirmwareDownload, data);
return data;
}
+
+ public validateSmartChargingTriggerReq(data: any): HttpTriggerSmartChargingRequest {
+ // Validate schema
+ this.validate(this.smartChargingTrigger, data);
+ return data;
+ }
}

Added Smartcharging trigger validation