Added ChargingProfile get/update/delete validation
ADD
src/assets/server/rest/v1/schemas/chargingstation/chargingprofile-delete.json
+{
+ "title": "Delete a Charging Profile Request",
+ "type": "object",
+ "properties": {
+ "ID": {
+ "$ref": "common.json#/definitions/id"
+ }
+ },
+ "required": [
+ "ID"
+ ]
+}

ADD
src/assets/server/rest/v1/schemas/chargingstation/chargingprofile-update.json
+{
+ "title": "Update a Charging Profile",
+ "type": "object",
+ "$ref": "chargingstation.json#/definitions/chargingProfile"
+}

ADD
src/assets/server/rest/v1/schemas/chargingstation/chargingprofiles-get.json
+{
+ "title": "Get Charging Profiles Request",
+ "type": "object",
+ "properties": {
+ "Search": {
+ "$ref": "common.json#/definitions/search"
+ },
+ "ChargingStationID": {
+ "$ref": "chargingstation.json#/definitions/id"
+ },
+ "ConnectorID": {
+ "$ref": "chargingstation.json#/definitions/connector/properties/connectorId"
+ },
+ "WithChargingStation": {
+ "type": "boolean",
+ "sanitize": "mongo"
+ },
+ "WithSiteArea": {
+ "type": "boolean",
+ "sanitize": "mongo"
+ },
+ "SiteID": {
+ "$ref": "common.json#/definitions/ids"
+ },
+ "Limit": {
+ "$ref": "common.json#/definitions/limit"
+ },
+ "SortFields": {
+ "$ref": "common.json#/definitions/sortFields"
+ },
+ "Skip": {
+ "$ref": "common.json#/definitions/skip"
+ },
+ "OnlyRecordCount": {
+ "$ref": "common.json#/definitions/onlyRecordCount"
+ },
+ "ProjectFields": {
+ "$ref": "common.json#/definitions/projectFields"
+ }
+ }
+}

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -468,7 +468,7 @@ export default class ChargingStationService {
public static async handleGetChargingProfiles(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = ChargingStationSecurity.filterChargingProfilesRequest(req.query);
+ const filteredRequest = ChargingStationValidator.getInstance().validateChargingProfilesGetReq(req.query);
// Check auth
if (!await Authorizations.canListChargingProfiles(req.user)) {
throw new AppAuthError({
@@ -508,7 +508,12 @@ export default class ChargingStationService {
withSiteArea: filteredRequest.WithSiteArea,
siteIDs: Authorizations.getAuthorizedSiteIDs(req.user, filteredRequest.SiteID ? filteredRequest.SiteID.split('|') : null),
},
- { limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.SortFields, onlyRecordCount: filteredRequest.OnlyRecordCount },
+ {
+ limit: filteredRequest.Limit,
+ skip: filteredRequest.Skip,
+ sort: UtilsService.httpSortFieldsToMongoDB(filteredRequest.SortFields),
+ onlyRecordCount: filteredRequest.OnlyRecordCount
+ },
projectFields
);
// Build the result
@@ -672,7 +677,7 @@ export default class ChargingStationService {
public static async handleUpdateChargingProfile(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = ChargingStationSecurity.filterChargingProfileUpdateRequest({ ...req.params, ...req.body });
+ const filteredRequest = ChargingStationValidator.getInstance().validateChargingProfileUpdateReq({ ...req.params, ...req.body });
// Check existence
const chargingStation = await ChargingStationStorage.getChargingStation(req.user.tenantID, filteredRequest.chargingStationID);
UtilsService.assertObjectExists(action, chargingStation, `Charging Station ID '${filteredRequest.chargingStationID}' does not exist.`,
@@ -729,7 +734,7 @@ export default class ChargingStationService {
public static async handleDeleteChargingProfile(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check existence
- const chargingProfileID = ChargingStationSecurity.filterChargingProfileRequestByID(req.query);
+ const chargingProfileID = ChargingStationValidator.getInstance().validateChargingProfileDeleteReq(req.query).ID;
// Get Profile
const chargingProfile = await ChargingStationStorage.getChargingProfile(req.user.tenantID, chargingProfileID);
UtilsService.assertObjectExists(action, chargingProfile, `Charging Profile ID '${chargingProfileID}' does not exist.`,

MODIFY
src/server/rest/v1/validator/ChargingStationValidator.ts
src/server/rest/v1/validator/ChargingStationValidator.ts
-import { HttpChargingStationCommandRequest, HttpChargingStationConnectorRequest, HttpChargingStationGetFirmwareRequest, HttpChargingStationLimitPowerRequest, HttpChargingStationOcppParametersRequest, HttpChargingStationOcppRequest, HttpChargingStationParamsUpdateRequest, HttpChargingStationRequest, HttpChargingStationsInErrorRequest, HttpChargingStationsRequest, HttpDownloadQrCodeRequest, HttpTriggerSmartChargingRequest } from '../../../../types/requests/HttpChargingStationRequest';
+import { HttpChargingProfilesRequest, HttpChargingProfilesUpdateRequest, HttpChargingStationCommandRequest, HttpChargingStationConnectorRequest, HttpChargingStationGetFirmwareRequest, HttpChargingStationLimitPowerRequest, HttpChargingStationOcppParametersRequest, HttpChargingStationOcppRequest, HttpChargingStationParamsUpdateRequest, HttpChargingStationRequest, HttpChargingStationsInErrorRequest, HttpChargingStationsRequest, HttpDownloadQrCodeRequest, HttpTriggerSmartChargingRequest } from '../../../../types/requests/HttpChargingStationRequest';
import { ChargingProfile } from '../../../../types/ChargingProfile';
import HttpByIDRequest from '../../../../types/requests/HttpByIDRequest';
@@ -16,13 +16,16 @@ export default class ChargingStationValidator extends SchemaValidator {
private chargingStationQRCodeGenerate: Schema;
private chargingStationQRCodeDownload: Schema;
private chargingStationOcppParametersGet: Schema;
- private chargingProfileCreate: Schema;
private chargingStationRequestOCPPParameters: Schema;
private chargingStationUpdateParameters: Schema;
private chargingStationLimitPower: Schema;
private chargingStationFirmwareDownload: Schema;
private smartChargingTrigger: Schema;
private chargingStationInErrorGet: Schema;
+ private chargingProfileCreate: Schema;
+ private chargingProfilesGet: Schema;
+ private chargingProfileDelete: Schema;
+ private chargingProfileUpdate: Schema;
private constructor() {
super('ChargingStationValidator');
@@ -33,13 +36,16 @@ export default class ChargingStationValidator extends SchemaValidator {
this.chargingStationQRCodeGenerate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-qrcode-generate.json`, 'utf8'));
this.chargingStationQRCodeDownload = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-qrcode-download.json`, 'utf8'));
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.chargingStationRequestOCPPParameters = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-ocpp-request-parameters.json`, 'utf8'));
this.chargingStationUpdateParameters = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-update-parameters.json`, 'utf8'));
this.chargingStationLimitPower = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-limit-power.json`, 'utf8'));
this.chargingStationFirmwareDownload = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-firmware-download.json`, 'utf8'));
this.smartChargingTrigger = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/smartcharging-trigger.json`, 'utf8'));
this.chargingStationInErrorGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstations-inerror-get.json`, 'utf8'));
+ this.chargingProfileCreate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingprofile-create.json`, 'utf8'));
+ this.chargingProfilesGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingprofiles-get.json`, 'utf8'));
+ this.chargingProfileDelete = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingprofile-delete.json`, 'utf8'));
+ this.chargingProfileUpdate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingprofile-update.json`, 'utf8'));
}
public static getInstance(): ChargingStationValidator {
@@ -133,4 +139,22 @@ export default class ChargingStationValidator extends SchemaValidator {
this.validate(this.chargingStationInErrorGet, data);
return data;
}
+
+ public validateChargingProfilesGetReq(data: any): HttpChargingProfilesRequest {
+ // Validate schema
+ this.validate(this.chargingProfilesGet, data);
+ return data;
+ }
+
+ public validateChargingProfileDeleteReq(data: any): HttpByIDRequest {
+ // Validate schema
+ this.validate(this.chargingProfileDelete, data);
+ return data;
+ }
+
+ public validateChargingProfileUpdateReq(data: any): ChargingProfile {
+ // Validate schema
+ this.validate(this.chargingProfileUpdate, data);
+ return data;
+ }
}

MODIFY
src/types/requests/HttpChargingStationRequest.ts
src/types/requests/HttpChargingStationRequest.ts
@@ -22,7 +22,6 @@ export interface HttpChargingProfilesRequest extends HttpDatabaseRequest {
WithSiteArea?: boolean;
SiteID?: string;
}
-
export interface HttpDownloadQrCodeRequest {
ChargingStationID?: string;
ConnectorID?: number;

Added ChargingProfile get/update/delete validation