Adapted get Charging Profile  Method
MODIFY
src/server/rest/service/ChargingStationService.ts
src/server/rest/service/ChargingStationService.ts
@@ -380,22 +380,23 @@ export default class ChargingStationService {
public static async handleGetChargingProfiles(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = ChargingStationSecurity.filterChargingStationProfilesRequest(req.query);
- UtilsService.assertIdIsProvided(action, filteredRequest.ChargeBoxID, MODULE_NAME, 'handleGetChargingProfiles', req.user);
+ const filteredRequest = ChargingStationSecurity.filterChargingProfilesRequest(req.query);
// Check auth
- if (!Authorizations.canReadChargingStation(req.user)) {
+ if (!Authorizations.canListChargingStations(req.user)) {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
action: Action.READ,
entity: Entity.CHARGING_STATION,
module: MODULE_NAME,
- method: 'handleGetChargingProfiles',
- value: filteredRequest.ChargeBoxID
+ method: 'handleGetChargingProfiles'
});
}
const chargingProfiles = await ChargingStationStorage.getChargingProfiles(req.user.tenantID,
- { chargingStationID: filteredRequest.ChargeBoxID, connectorID: filteredRequest.ConnectorID },
+ { chargingStationID: filteredRequest.ChargeBoxID,
+ connectorID: filteredRequest.ConnectorID,
+ withChargingStation: filteredRequest.WithChargingStation,
+ withSiteArea: filteredRequest.WithSiteArea },
{ limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.Sort, onlyRecordCount: filteredRequest.OnlyRecordCount });
res.json(chargingProfiles);
next();

MODIFY
src/server/rest/service/security/ChargingStationSecurity.ts
src/server/rest/service/security/ChargingStationSecurity.ts
@@ -169,10 +169,13 @@ export default class ChargingStationSecurity {
return { ChargeBoxID: sanitize(request.ChargeBoxID) };
}
- public static filterChargingStationProfilesRequest(request: any): HttpChargingProfilesRequest {
+ public static filterChargingProfilesRequest(request: any): HttpChargingProfilesRequest {
const filteredRequest: HttpChargingProfilesRequest = {} as HttpChargingProfilesRequest;
+ filteredRequest.Search = sanitize(request.Search),
filteredRequest.ChargeBoxID = sanitize(request.ChargeBoxID);
filteredRequest.ConnectorID = sanitize(request.ConnectorID);
+ filteredRequest.WithChargingStation = UtilsSecurity.filterBoolean(request.WithChargingStation);
+ filteredRequest.WithSiteArea = UtilsSecurity.filterBoolean(request.WithSiteArea);
UtilsSecurity.filterSkipAndLimit(request, filteredRequest);
UtilsSecurity.filterSort(request, filteredRequest);
return filteredRequest;

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -12,6 +12,7 @@ import DbParams from '../../types/database/DbParams';
import Logging from '../../utils/Logging';
import { OCPPFirmwareStatus } from '../../types/ocpp/OCPPServer';
import { ServerAction } from '../../types/Server';
+import SiteAreaStorage from './SiteAreaStorage';
import TenantComponents from '../../types/TenantComponents';
import TenantStorage from './TenantStorage';
import Utils from '../../utils/Utils';
@@ -702,7 +703,7 @@ export default class ChargingStationStorage {
public static async getChargingProfiles(tenantID: string,
params: {
chargingStationID?: string; connectorID?: number; chargingProfileID?: string;
- profilePurposeType?: ChargingProfilePurposeType; transactionId?: number;
+ profilePurposeType?: ChargingProfilePurposeType; transactionId?: number; withChargingStation?: boolean; withSiteArea?: boolean;
} = {},
dbParams: DbParams, projectFields?: string[]): Promise<DataResult<ChargingProfile>> {
// Debug
@@ -743,6 +744,7 @@ export default class ChargingStationStorage {
$match: filters
});
}
+
// Limit records?
if (!dbParams.onlyRecordCount) {
aggregation.push({ $limit: Constants.DB_RECORD_COUNT_CEIL });
@@ -784,12 +786,29 @@ export default class ChargingStationStorage {
aggregation.push({
$limit: dbParams.limit
});
+ if (params.withChargingStation || params.withSiteArea) {
+ DatabaseUtils.pushChargingStationLookupInAggregation({
+ tenantID, aggregation, localField: 'chargingStationID', foreignField: '_id',
+ asField: 'chargingStation',
+ oneToOneCardinality: true,
+ oneToOneCardinalityNotNull: false
+ });
+ }
// Project
DatabaseUtils.projectFields(aggregation, projectFields);
// Read DB
const chargingProfilesMDB = await global.database.getCollection<ChargingProfile>(tenantID, 'chargingprofiles')
.aggregate(aggregation, { collation: { locale: Constants.DEFAULT_LOCALE, strength: 2 }, allowDiskUse: true })
.toArray();
+
+ if (params.withSiteArea) {
+ for (const chargingProfile of chargingProfilesMDB) {
+ if (chargingProfile.chargingStation.siteAreaID) {
+ chargingProfile.siteArea = await SiteAreaStorage.getSiteArea(tenantID, chargingProfile.chargingStation.siteAreaID);
+ }
+ }
+ }
+
// Debug
Logging.traceEnd(MODULE_NAME, 'getChargingProfiles', uniqueTimerID, { params, dbParams });
return {

MODIFY
src/types/ChargingProfile.ts
src/types/ChargingProfile.ts
+import ChargingStation from './ChargingStation';
+import SiteArea from './SiteArea';
+
export interface ChargingProfile {
id?: string;
chargingStationID: string;
+ chargingStation?: ChargingStation;
chargePointID: number;
connectorID?: number;
+ siteArea?: SiteArea;
profile: Profile;
}

MODIFY
src/types/requests/HttpChargingStationRequest.ts
src/types/requests/HttpChargingStationRequest.ts
@@ -19,8 +19,11 @@ export interface HttpChargingStationLimitPowerRequest {
}
export interface HttpChargingProfilesRequest extends HttpDatabaseRequest {
- ChargeBoxID: string;
- ConnectorID: number;
+ Search?: string;
+ ChargeBoxID?: string;
+ ConnectorID?: number;
+ WithChargingStation?: boolean;
+ WithSiteArea?: boolean;
}
export interface HttpChargingStationsRequest extends HttpDatabaseRequest {

Adapted get Charging Profile  Method