Added CS QRCode download validation
ADD
src/assets/server/rest/v1/schemas/chargingstation/chargingstation-qrcode-download.json
+{
+ "title": "Generate QRCode for Charging Station",
+ "type": "object",
+ "properties": {
+ "ChargingStationID": {
+ "$ref": "chargingstation.json#/definitions/id"
+ },
+ "ConnectorID": {
+ "$ref": "chargingstation.json#/definitions/connectorIDs"
+ },
+ "SiteAreaID": {
+ "$ref": "common.json#/definitions/ids"
+ },
+ "SiteID": {
+ "$ref": "common.json#/definitions/ids"
+ },
+ "ProjectFields": {
+ "$ref": "common.json#/definitions/projectFields"
+ }
+ },
+ "anyOf": [
+ {
+ "required": ["ChargingStationID"]
+ },
+ {
+ "required": ["SiteAreaID"]
+ },
+ {
+ "required": ["SiteID"]
+ }
+ ]
+}

ADD
src/assets/server/rest/v1/schemas/chargingstation/chargingstation-qrcode-generate.json
+{
+ "title": "Generate QRCode for Charging Station",
+ "type": "object",
+ "properties": {
+ "ChargingStationID": {
+ "$ref": "chargingstation.json#/definitions/id"
+ },
+ "ConnectorID": {
+ "$ref": "chargingstation.json#/definitions/connectorID"
+ },
+ "ProjectFields": {
+ "$ref": "common.json#/definitions/projectFields"
+ }
+ },
+ "required": [
+ "ChargingStationID", "ConnectorID"
+ ]
+}

MODIFY
src/assets/server/rest/v1/schemas/chargingstation/chargingstation.json
src/assets/server/rest/v1/schemas/chargingstation/chargingstation.json
"type": "number",
"sanitize": "mongo"
},
+ "connectorIDs": {
+ "type": "string",
+ "pattern": "^(\\d\\|?)*$",
+ "sanitize": "mongo"
+ },
"chargingProfilePurpose": {
"type": "string",
"sanitize": "mongo"

MODIFY
src/assets/server/rest/v1/schemas/chargingstation/chargingstations-get.json
src/assets/server/rest/v1/schemas/chargingstation/chargingstations-get.json
"type": "string",
"sanitize": "mongo"
},
- "ChargeBoxID": {
+ "ChargingStationID": {
"$ref": "chargingstation.json#/definitions/id"
},
"IncludeDeleted": {

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -998,7 +998,7 @@ export default class ChargingStationService {
public static async handleDownloadQrCodesPdf(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = ChargingStationSecurity.filterDownloadQrCodesPdfRequest(req.query);
+ const filteredRequest = ChargingStationValidator.getInstance().validateChargingStationQRCodeDownloadReq(req.query);
// Check
if (!filteredRequest.SiteID && !filteredRequest.SiteAreaID && !filteredRequest.ChargingStationID) {
throw new AppError({

MODIFY
src/server/rest/v1/validator/ChargingStationValidator.ts
src/server/rest/v1/validator/ChargingStationValidator.ts
-import { HttpChargingStationCommandRequest, HttpChargingStationConnectorRequest, HttpChargingStationsRequest } from '../../../../types/requests/HttpChargingStationRequest';
+import { HttpChargingStationCommandRequest, HttpChargingStationConnectorRequest, HttpChargingStationsRequest, HttpDownloadQrCodeRequest } from '../../../../types/requests/HttpChargingStationRequest';
import HttpByIDRequest from '../../../../types/requests/HttpByIDRequest';
import Schema from './Schema';
@@ -13,6 +13,7 @@ export default class ChargingStationValidator extends SchemaValidator {
private chargingStationDelete: Schema;
private chargingStationAction: Schema;
private chargingStationQRCodeGenerate: Schema;
+ private chargingStationQRCodeDownload: Schema;
private constructor() {
@@ -22,6 +23,7 @@ export default class ChargingStationValidator extends SchemaValidator {
this.chargingStationDelete = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-delete.json`, 'utf8'));
this.chargingStationAction = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/chargingstation/chargingstation-action.json`, 'utf8'));
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'));
}
public static getInstance(): ChargingStationValidator {
@@ -60,4 +62,10 @@ export default class ChargingStationValidator extends SchemaValidator {
this.validate(this.chargingStationQRCodeGenerate, data);
return data;
}
+
+ public validateChargingStationQRCodeDownloadReq(data: any): HttpDownloadQrCodeRequest {
+ // Validate schema
+ this.validate(this.chargingStationQRCodeDownload, data);
+ return data;
+ }
}

MODIFY
src/server/rest/v1/validator/SchemaValidator.ts
src/server/rest/v1/validator/SchemaValidator.ts
@@ -25,7 +25,7 @@ export default class SchemaValidator {
useDefaults: boolean; coerceTypes: boolean;
} = {
allErrors: true,
- removeAdditional: 'all',
+ removeAdditional: 'failing',
useDefaults: true,
coerceTypes: true
}) {

Added CS QRCode download validation