Improved GPS regex check
MODIFY
src/server/rest/v1/validator/ChargingStationValidator.ts
src/server/rest/v1/validator/ChargingStationValidator.ts
@@ -4,6 +4,7 @@ import { ChargingProfile } from '../../../../types/ChargingProfile';
import HttpByIDRequest from '../../../../types/requests/HttpByIDRequest';
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from './SchemaValidator';
+import Utils from '../../../../utils/Utils';
import fs from 'fs';
import global from '../../../../types/GlobalType';
@@ -52,6 +53,12 @@ export default class ChargingStationValidator extends SchemaValidator {
public validateChargingStationsGetReq(data: any): HttpChargingStationsRequest {
// Validate schema
this.validate(this.chargingStationsGet, data);
+ if (Utils.containsGPSCoordinates([data.LocLongitude, data.LocLatitude])) {
+ data.LocCoordinates = [
+ Utils.convertToFloat(data.LocLongitude),
+ Utils.convertToFloat(data.LocLatitude)
+ ];
+ }
return data;
}

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -256,7 +256,7 @@ export default class ChargingStationStorage {
// Connector Status
if (params.connectorStatuses) {
filters['connectors.status'] = { $in: params.connectorStatuses };
- filters.inactive = true;
+ filters.inactive = false;
// Filter connectors array
aggregation.push({
'$addFields': {

MODIFY
src/utils/Constants.ts
src/utils/Constants.ts
@@ -286,8 +286,8 @@ export default class Constants {
public static readonly MAX_DATE = new Date('9999-12-31Z23:59:59:999');
public static readonly MIN_DATE = new Date('1970-01-01Z00:00:00:000');
- public static readonly REGEX_VALIDATION_LATITUDE = /^-?([1-8]?[0-9]|[0-9]0)\.{0,1}[0-9]*$/;
- public static readonly REGEX_VALIDATION_LONGITUDE = /^-?([1]?[0-7][0-9]|[1]?[0-8][0]|[1-9]?[0-9])\.{0,1}[0-9]*$/;
+ public static readonly REGEX_VALIDATION_LATITUDE = /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?)$/;
+ public static readonly REGEX_VALIDATION_LONGITUDE = /^[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/;
public static readonly MAX_GPS_DISTANCE_METERS = 40000000; // Earth
public static readonly SENSITIVE_DATA = Object.freeze([

Improved GPS regex check