Fixed with db aggregation
MODIFY
src/server/rest/service/ChargingStationService.ts
src/server/rest/service/ChargingStationService.ts
@@ -339,7 +339,8 @@ export default class ChargingStationService {
chargingStationIDs: filteredRequest.ChargeBoxID ? filteredRequest.ChargeBoxID.split('|') : null,
connectorID: filteredRequest.ConnectorID,
withChargingStation: filteredRequest.WithChargingStation,
- withSiteArea: true },
+ withSiteArea: true,
+ siteIDs: Authorizations.getAuthorizedSiteIDs(req.user, filteredRequest.SiteID ? filteredRequest.SiteID.split('|') : null), },
{ limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.Sort, onlyRecordCount: filteredRequest.OnlyRecordCount });
// Build the result
ChargingStationSecurity.filterChargingProfilesResponse(chargingProfiles, req.user);

MODIFY
src/server/rest/service/security/ChargingStationSecurity.ts
src/server/rest/service/security/ChargingStationSecurity.ts
@@ -196,11 +196,10 @@ export default class ChargingStationSecurity {
}
for (const chargingProfile of chargingProfiles.result) {
const filteredChargingProfile = this.filterChargingProfileResponse(chargingProfile, loggedUser);
- if (filteredChargingProfile && Object.entries(filteredChargingProfile).length !== 0) {
+ if (filteredChargingProfile) {
filteredChargingProfiles.push(filteredChargingProfile);
}
}
- chargingProfiles.count = filteredChargingProfiles.length;
chargingProfiles.result = filteredChargingProfiles;
}
@@ -280,6 +279,7 @@ export default class ChargingStationSecurity {
filteredRequest.ConnectorID = sanitize(request.ConnectorID);
filteredRequest.WithChargingStation = UtilsSecurity.filterBoolean(request.WithChargingStation);
filteredRequest.WithSiteArea = UtilsSecurity.filterBoolean(request.WithSiteArea);
+ filteredRequest.SiteID = sanitize(request.SiteID);
UtilsSecurity.filterSkipAndLimit(request, filteredRequest);
UtilsSecurity.filterSort(request, filteredRequest);
return filteredRequest;

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -658,7 +658,7 @@ export default class ChargingStationStorage {
public static async getChargingProfiles(tenantID: string,
params: {
search?: string; chargingStationIDs?: string[]; connectorID?: number; chargingProfileID?: string;
- profilePurposeType?: ChargingProfilePurposeType; transactionId?: number; withChargingStation?: boolean; withSiteArea?: boolean;
+ profilePurposeType?: ChargingProfilePurposeType; transactionId?: number; withChargingStation?: boolean; withSiteArea?: boolean; siteIDs?: string[];
} = {},
dbParams: DbParams, projectFields?: string[]): Promise<DataResult<ChargingProfile>> {
// Debug
@@ -762,6 +762,17 @@ export default class ChargingStationStorage {
// Convert
DatabaseUtils.pushConvertObjectIDToString(aggregation, 'chargingStation.siteAreaID');
DatabaseUtils.pushConvertObjectIDToString(aggregation, 'chargingStation.siteArea.siteID');
+ // Check Site ID
+ if (!Utils.isEmptyArray(params.siteIDs)) {
+ // Build filter
+ aggregation.push({
+ $match: {
+ 'chargingStation.siteArea.siteID': {
+ $in: params.siteIDs.map((id) => id)
+ }
+ }
+ });
+ }
}
// Project
DatabaseUtils.projectFields(aggregation, projectFields);

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

Fixed with db aggregation