Added position filter in Sites
MODIFY
src/server/rest/service/ChargingStationService.ts
src/server/rest/service/ChargingStationService.ts
@@ -1162,8 +1162,6 @@ export default class ChargingStationService {
// Get Charging Stations
const chargingStations = await ChargingStationStorage.getChargingStations(req.user.tenantID,
{
- posCoordinates: filteredRequest.PosCoordinates,
- posMaxDistanceMeters: filteredRequest.PosMaxDistanceMeters,
search: filteredRequest.Search,
withNoSiteArea: filteredRequest.WithNoSiteArea,
withSite: filteredRequest.WithSite,
@@ -1172,7 +1170,9 @@ export default class ChargingStationService {
issuer: filteredRequest.Issuer,
siteIDs: Authorizations.getAuthorizedSiteIDs(req.user, filteredRequest.SiteID ? filteredRequest.SiteID.split('|') : null),
siteAreaIDs: (filteredRequest.SiteAreaID ? filteredRequest.SiteAreaID.split('|') : null),
- includeDeleted: filteredRequest.IncludeDeleted
+ includeDeleted: filteredRequest.IncludeDeleted,
+ posCoordinates: filteredRequest.PosCoordinates,
+ posMaxDistanceMeters: filteredRequest.PosMaxDistanceMeters,
},
{
limit: filteredRequest.Limit,

MODIFY
src/server/rest/service/SiteService.ts
src/server/rest/service/SiteService.ts
@@ -382,7 +382,9 @@ export default class SiteService {
siteIDs: Authorizations.getAuthorizedSiteIDs(req.user, filteredRequest.SiteID ? filteredRequest.SiteID.split('|') : null),
withCompany: filteredRequest.WithCompany,
excludeSitesOfUserID: filteredRequest.ExcludeSitesOfUserID,
- withAvailableChargingStations: filteredRequest.WithAvailableChargers
+ withAvailableChargingStations: filteredRequest.WithAvailableChargers,
+ posCoordinates: filteredRequest.PosCoordinates,
+ posMaxDistanceMeters: filteredRequest.PosMaxDistanceMeters,
},
{
limit: filteredRequest.Limit,

MODIFY
src/server/rest/service/security/SiteSecurity.ts
src/server/rest/service/security/SiteSecurity.ts
@@ -73,6 +73,18 @@ export default class SiteSecurity {
filteredRequest.ExcludeSitesOfUserID = sanitize(request.ExcludeSitesOfUserID);
filteredRequest.WithCompany = UtilsSecurity.filterBoolean(request.WithCompany);
filteredRequest.WithAvailableChargers = UtilsSecurity.filterBoolean(request.WithAvailableChargers);
+ if (Utils.containsGPSCoordinates([request.PosLongitude, request.PosLatitude])) {
+ filteredRequest.PosCoordinates = [
+ Utils.convertToFloat(sanitize(request.PosLongitude)),
+ Utils.convertToFloat(sanitize(request.PosLatitude))
+ ];
+ if (request.PosMaxDistanceMeters) {
+ request.PosMaxDistanceMeters = Utils.convertToInt(sanitize(request.PosMaxDistanceMeters));
+ if (request.PosMaxDistanceMeters > 0) {
+ filteredRequest.PosMaxDistanceMeters = request.PosMaxDistanceMeters;
+ }
+ }
+ }
UtilsSecurity.filterSkipAndLimit(request, filteredRequest);
UtilsSecurity.filterSort(request, filteredRequest);
return filteredRequest;

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -127,7 +127,7 @@ export default class ChargingStationStorage {
dbParams.skip = Utils.checkRecordSkip(dbParams.skip);
// Create Aggregation
const aggregation = [];
- // User coordinates
+ // Position coordinates
if (Utils.containsGPSCoordinates(params.posCoordinates)) {
aggregation.push({
$geoNear: {

MODIFY
src/storage/mongodb/SiteStorage.ts
src/storage/mongodb/SiteStorage.ts
@@ -310,6 +310,7 @@ export default class SiteStorage {
search?: string; companyIDs?: string[]; withAutoUserAssignment?: boolean; siteIDs?: string[];
userID?: string; excludeSitesOfUserID?: boolean; issuer?: boolean;
withAvailableChargingStations?: boolean; withOnlyChargingStations?: boolean; withCompany?: boolean;
+ posCoordinates?: number[]; posMaxDistanceMeters?: number;
} = {},
dbParams: DbParams, projectFields?: string[]): Promise<DataResult<Site>> {
// Debug
@@ -322,6 +323,20 @@ export default class SiteStorage {
const skip = Utils.checkRecordSkip(dbParams.skip);
// Create Aggregation
const aggregation = [];
+ // Position coordinates
+ if (Utils.containsGPSCoordinates(params.posCoordinates)) {
+ aggregation.push({
+ $geoNear: {
+ near: {
+ type: 'Point',
+ coordinates: params.posCoordinates
+ },
+ distanceField: 'distanceMeters',
+ maxDistance: params.posMaxDistanceMeters > 0 ? params.posMaxDistanceMeters : Constants.MAX_GPS_DISTANCE_METERS,
+ spherical: true
+ }
+ });
+ }
// Search filters
const filters: any = {};
if (params.search) {

MODIFY
src/types/requests/HttpSiteRequest.ts
src/types/requests/HttpSiteRequest.ts
@@ -14,6 +14,8 @@ export interface HttpSitesRequest extends HttpDatabaseRequest {
SiteID: string;
ExcludeSitesOfUserID: boolean;
Search: string;
+ PosCoordinates?: number[];
+ PosMaxDistanceMeters?: number;
}
export interface HttpSiteAssignUsersRequest {

Added position filter in Sites