Reduced amount of data returned by getChargingStation
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -56,11 +56,11 @@ export default class Authorizations {
public static async canStartTransaction(loggedUser: UserToken, chargingStation: ChargingStation): Promise<boolean> {
let context: AuthorizationContext;
if (Utils.isComponentActiveFromToken(loggedUser, TenantComponents.ORGANIZATION)) {
- if (!chargingStation || !chargingStation.siteArea || !chargingStation.site) {
+ if (!chargingStation || !chargingStation.siteID || !chargingStation.siteAreaID) {
return false;
}
context = {
- site: chargingStation.site.id,
+ site: chargingStation.siteID,
sites: loggedUser.sites,
sitesAdmin: loggedUser.sitesAdmin
};
@@ -740,23 +740,11 @@ export default class Authorizations {
return result;
}
- public static async isChargingStationValidInOrganization(action: ServerAction, tenant: Tenant, chargingStation: ChargingStation): Promise<boolean> {
+ public static isChargingStationValidInOrganization(action: ServerAction, tenant: Tenant, chargingStation: ChargingStation): boolean {
// Org component enabled?
if (Utils.isTenantComponentActive(tenant, TenantComponents.ORGANIZATION)) {
- let foundSiteArea = true;
- // Site Area -----------------------------------------------
- if (!chargingStation.siteAreaID) {
- foundSiteArea = false;
- } else if (!chargingStation.siteArea) {
- chargingStation.siteArea = await SiteAreaStorage.getSiteArea(
- tenant, chargingStation.siteAreaID, { withSite: true });
- if (!chargingStation.siteArea) {
- foundSiteArea = false;
- }
- }
- // Site is mandatory
- if (!foundSiteArea) {
- // Reject Site Not Found
+ // Check Site Area
+ if (!chargingStation.siteAreaID || !chargingStation.siteArea) {
throw new BackendError({
source: chargingStation.id,
action: action,
@@ -765,10 +753,8 @@ export default class Authorizations {
detailedMessages: { chargingStation }
});
}
- // Site -----------------------------------------------------
- chargingStation.site = await SiteStorage.getSite(tenant, chargingStation.siteID);
- if (!chargingStation.site) {
- // Reject Site Not Found
+ // Check Site
+ if (!chargingStation.siteID) {
throw new BackendError({
source: chargingStation.id,
action: action,
@@ -784,7 +770,7 @@ export default class Authorizations {
private static async isTagIDAuthorizedOnChargingStation(tenant: Tenant, chargingStation: ChargingStation,
transaction: Transaction, tagID: string, action: ServerAction, authAction: Action): Promise<{user: User, tag?: Tag}> {
// Check Organization
- if (await Authorizations.isChargingStationValidInOrganization(action, tenant, chargingStation)) {
+ if (Authorizations.isChargingStationValidInOrganization(action, tenant, chargingStation)) {
// Access Control is disabled?
if (!chargingStation.siteArea.accessControl) {
// No ACL: Always try to get the user

MODIFY
src/server/ocpp/json/JsonWSConnection.ts
src/server/ocpp/json/JsonWSConnection.ts
@@ -85,7 +85,8 @@ export default class JsonWSConnection extends WSConnection {
}
};
// Update the Charging Station
- const chargingStation = await ChargingStationStorage.getChargingStation(this.getTenant(), this.getChargingStationID(), {}, ['id']);
+ const chargingStation = await ChargingStationStorage.getChargingStation(
+ this.getTenant(), this.getChargingStationID(), { issuer: true }, ['id']);
if (chargingStation) {
// Update Last Seen
await ChargingStationStorage.saveChargingStationLastSeen(this.getTenant(),

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -82,7 +82,7 @@ export default class OCPPService {
});
}
// Get Charging Station
- let chargingStation = await ChargingStationStorage.getChargingStation(tenant, headers.chargeBoxIdentity);
+ let chargingStation = await ChargingStationStorage.getChargingStation(tenant, headers.chargeBoxIdentity, { issuer: true });
if (!chargingStation) {
// Create Charging Station
chargingStation = await this.checkAndCreateChargingStation(tenant, bootNotification, headers);
@@ -1663,13 +1663,10 @@ export default class OCPPService {
startTransaction.tagID = startTransaction.idTag;
// Organization
if (Utils.isTenantComponentActive(tenant, TenantComponents.ORGANIZATION)) {
- // Set the Site Area ID
+ // Set the Organization IDs
+ startTransaction.companyID = chargingStation.companyID;
+ startTransaction.siteID = chargingStation.siteID;
startTransaction.siteAreaID = chargingStation.siteAreaID;
- // Set the Site ID. ChargingStation$siteArea$site checked by TagIDAuthorized.
- if (chargingStation.site) {
- startTransaction.siteID = chargingStation.site.id;
- startTransaction.companyID = chargingStation.site.companyID;
- }
}
}

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
@@ -1337,7 +1337,7 @@ export default class OCPPUtils {
source: chargingProfile.chargingStationID,
action: ServerAction.CHARGING_PROFILE_DELETE,
module: MODULE_NAME, method: 'clearAndDeleteChargingProfile',
- message: `Charging Station '${chargingStation.id}' does not support the Charging Profiles`,
+ message: 'Charging Station does not support the Charging Profiles',
});
}
// Get Vendor Instance
@@ -1549,7 +1549,7 @@ export default class OCPPUtils {
let chargingStation: ChargingStation;
try {
chargingStation = await ChargingStationStorage.getChargingStation(
- tenant, ocppHeader.chargeBoxIdentity);
+ tenant, ocppHeader.chargeBoxIdentity, { withSiteArea: true });
if (!chargingStation) {
throw new BackendError({
source: ocppHeader.chargeBoxIdentity,

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -614,7 +614,7 @@ export default class ChargingStationService {
// Check ConnectorID
UtilsService.assertIdIsProvided(action, filteredRequest.ConnectorID, MODULE_NAME, 'handleGenerateQrCodeForConnector', req.user);
// Get the Charging Station`
- const chargingStation: ChargingStation = await ChargingStationStorage.getChargingStation(req.tenant, filteredRequest.ChargingStationID);
+ const chargingStation = await ChargingStationStorage.getChargingStation(req.tenant, filteredRequest.ChargingStationID);
// Found ChargingStation ?
UtilsService.assertObjectExists(action, chargingStation, `Charging Station ID '${filteredRequest.ChargingStationID}' does not exist`,
MODULE_NAME, 'handleGetChargingStationOcppParameters', req.user);
@@ -913,6 +913,7 @@ export default class ChargingStationService {
// Check and Get Charging Station
const chargingStation = await UtilsService.checkAndGetChargingStationAuthorization(
req.tenant, req.user, filteredRequest.ID, action, null, {
+ withSiteArea: true,
withLogo: true
}, true);
res.json(chargingStation);
@@ -1145,7 +1146,7 @@ export default class ChargingStationService {
UtilsService.assertIdIsProvided(action, filteredRequest.chargingStationID, MODULE_NAME, 'handleAction', req.user);
// Get the Charging station
const chargingStation = await UtilsService.checkAndGetChargingStationAuthorization(
- req.tenant, req.user, filteredRequest.chargingStationID, action);
+ req.tenant, req.user, filteredRequest.chargingStationID, action, null, { withSite: true, withSiteArea: true });
let result: any;
switch (command) {
// Remote Stop Transaction / Unlock Connector
@@ -1794,7 +1795,7 @@ export default class ChargingStationService {
});
}
// Check Charging Station
- await Authorizations.isChargingStationValidInOrganization(action, req.tenant, chargingStation);
+ Authorizations.isChargingStationValidInOrganization(action, req.tenant, chargingStation);
// Execute it
const result = await ChargingStationService.executeChargingStationCommand(
req.tenant, req.user, chargingStation, action, command, { tagID: tag.id, connectorId: filteredRequest.args.connectorId });

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -134,11 +134,12 @@ export default class ChargingStationStorage {
}
public static async getChargingStation(tenant: Tenant, id: string = Constants.UNKNOWN_STRING_ID,
- params: { includeDeleted?: boolean, issuer?: boolean; siteIDs?: string[] } = {}, projectFields?: string[]): Promise<ChargingStation> {
+ params: { includeDeleted?: boolean, issuer?: boolean; siteIDs?: string[]; withSiteArea?: boolean; withSite?: boolean; } = {},
+ projectFields?: string[]): Promise<ChargingStation> {
const chargingStationsMDB = await ChargingStationStorage.getChargingStations(tenant, {
chargingStationIDs: [id],
- withSite: true,
- withSiteArea: true,
+ withSite: params.withSite,
+ withSiteArea: params.withSiteArea,
includeDeleted: params.includeDeleted,
issuer: params.issuer,
siteIDs: params.siteIDs,

Reduced amount of data returned by getChargingStation