Fetching the charging stations with existing methods
MODIFY
src/server/rest/v1/service/SiteService.ts
src/server/rest/v1/service/SiteService.ts
@@ -394,14 +394,18 @@ export default class SiteService {
site.companyID = filteredRequest.companyID;
if (Utils.objectHasProperty(filteredRequest, 'public')) {
if (!filteredRequest.public) {
- const publicChargingStation = await ChargingStationStorage.getPublicChargingStationInSite(req.tenant, {
- siteID: site.id
+ const publicChargingStations = await ChargingStationStorage.getChargingStations(req.tenant, {
+ siteIDs: [site.id],
+ public: true,
+ }, {
+ skip: 0,
+ limit: 1,
} , ['id']);
- if (publicChargingStation) {
+ if (publicChargingStations.count > 0) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.FEATURE_NOT_SUPPORTED_ERROR,
- message: `Cannot set site ${site.name} to private as charging station ${publicChargingStation.id} under site is public`,
+ message: `Cannot set site ${site.name} to private as charging station ${publicChargingStations.result[0].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,15 +176,6 @@ 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;

Fetching the charging stations with existing methods