Add positioning in Site Area
MODIFY
src/server/rest/service/SiteAreaService.ts
src/server/rest/service/SiteAreaService.ts
@@ -303,6 +303,8 @@ export default class SiteAreaService {
withChargingStations: filteredRequest.WithChargeBoxes,
withAvailableChargingStations: filteredRequest.WithAvailableChargers,
siteIDs: Authorizations.getAuthorizedSiteIDs(req.user, filteredRequest.SiteID ? filteredRequest.SiteID.split('|') : null),
+ posCoordinates: filteredRequest.PosCoordinates,
+ posMaxDistanceMeters: filteredRequest.PosMaxDistanceMeters,
},
{ limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.Sort, onlyRecordCount: filteredRequest.OnlyRecordCount },
['id', 'name', 'siteID', 'maximumPower', 'numberOfPhases', 'accessControl', 'smartCharging', 'address.coordinates', 'address.city', 'address.country', 'site.id', 'site.name', 'issuer']

MODIFY
src/server/rest/service/security/SiteAreaSecurity.ts
src/server/rest/service/security/SiteAreaSecurity.ts
@@ -51,6 +51,18 @@ export default class SiteAreaSecurity {
if (request.Issuer) {
filteredRequest.Issuer = UtilsSecurity.filterBoolean(request.Issuer);
}
+ 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/SiteAreaStorage.ts
src/storage/mongodb/SiteAreaStorage.ts
@@ -154,7 +154,8 @@ export default class SiteAreaStorage {
public static async getSiteAreas(tenantID: string,
params: {
siteAreaIDs?: string[]; search?: string; siteIDs?: string[]; withSite?: boolean; issuer?: boolean;
- withChargingStations?: boolean; withOnlyChargingStations?: boolean; withAvailableChargingStations?: boolean; smartCharging?: boolean;
+ withChargingStations?: boolean; withOnlyChargingStations?: boolean; withAvailableChargingStations?: boolean;
+ posCoordinates?: number[]; posMaxDistanceMeters?: number; smartCharging?: boolean;
} = {},
dbParams: DbParams, projectFields?: string[]): Promise<DataResult<SiteArea>> {
// Debug
@@ -165,6 +166,22 @@ export default class SiteAreaStorage {
const limit = Utils.checkRecordLimit(dbParams.limit);
// Check Skip
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
+ }
+ });
+ }
// Set the filters
const filters: any = {};
// Otherwise check if search is present
@@ -191,8 +208,6 @@ export default class SiteAreaStorage {
if (params.smartCharging === true || params.smartCharging === false) {
filters.smartCharging = params.smartCharging;
}
- // Create Aggregation
- const aggregation = [];
// Filters
if (filters) {
aggregation.push({

MODIFY
src/types/requests/HttpSiteAreaRequest.ts
src/types/requests/HttpSiteAreaRequest.ts
@@ -13,6 +13,8 @@ export interface HttpSiteAreasRequest extends HttpDatabaseRequest {
WithSite?: boolean;
WithChargeBoxes?: boolean;
WithAvailableChargers: boolean;
+ PosCoordinates?: number[];
+ PosMaxDistanceMeters?: number;
}
export interface HttpSiteAreaConsumptionsRequest {

MODIFY
src/types/requests/HttpSiteRequest.ts
src/types/requests/HttpSiteRequest.ts
@@ -6,6 +6,7 @@ export interface HttpSiteRequest extends HttpByIDRequest {
}
export interface HttpSitesRequest extends HttpDatabaseRequest {
+ Search: string;
Issuer: boolean;
WithAvailableChargers: boolean;
WithCompany: boolean;
@@ -13,7 +14,6 @@ export interface HttpSitesRequest extends HttpDatabaseRequest {
CompanyID: string;
SiteID: string;
ExcludeSitesOfUserID: boolean;
- Search: string;
PosCoordinates?: number[];
PosMaxDistanceMeters?: number;
}

Add positioning in Site Area