Additional changes as requested
MODIFY
src/server/rest/v1/service/SiteService.ts
src/server/rest/v1/service/SiteService.ts
@@ -394,13 +394,14 @@ export default class SiteService {
site.companyID = filteredRequest.companyID;
if (Utils.objectHasProperty(filteredRequest, 'public')) {
if (!filteredRequest.public) {
- const publicChargingStations = (await ChargingStationStorage.getChargingStations(req.tenant,
- { siteIDs: [site.id], public: true, withSiteArea: true }, Constants.DB_PARAMS_MAX_LIMIT)).result;
- if (!Utils.isEmptyArray(publicChargingStations)) {
+ const publicChargingStation = await ChargingStationStorage.getPublicChargingStationInSite(req.tenant, {
+ siteID: site.id
+ } , ['id']);
+ if (publicChargingStation) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
- message: 'Cannot set site to private as charging stations in site are public',
+ message: `Cannot set site ${site.name} to private as charging station ${publicChargingStation.id} under site is public`,
module: MODULE_NAME, method: 'handleUpdateSite',
user: req.user,
});

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -176,6 +176,15 @@ export default class ChargingStationStorage {
return chargingStationsMDB.count === 1 ? chargingStationsMDB.result[0] : null;
}
+ public static async getPublicChargingStationInSite(tenant: Tenant, params: { siteID: string, },
+ projectFields?: string[]): Promise<ChargingStation> {
+ const chargingStationsMDB = await ChargingStationStorage.getChargingStations(tenant, {
+ siteIDs: [params.siteID],
+ public: true,
+ }, Constants.DB_PARAMS_SINGLE_RECORD, projectFields);
+ return chargingStationsMDB.count >= 1 ? chargingStationsMDB.result[0] : null;
+ }
+
public static async getChargingStations(tenant: Tenant,
params: {
search?: string; chargingStationIDs?: string[]; chargingStationSerialNumbers?: string[]; siteAreaIDs?: string[]; withNoSiteArea?: boolean;

Additional changes as requested