Make Site public
MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIMapping.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIMapping.ts
@@ -162,32 +162,14 @@ export default class OCPIMapping {
// Result
const ocpiLocationsResult: DataResult<OCPILocation> = { count: 0, result: [] };
// Get all sites
- const sites = await SiteStorage.getSites(tenant.id, { issuer: true, withOnlyChargingStations: true }, { limit, skip });
+ const sites = await SiteStorage.getSites(tenant.id,
+ { issuer: true, withOnlyChargingStations: true, onlyPublicSite: true }, { limit, skip });
// Convert Sites to Locations
for (const site of sites.result) {
- let foundPublicChargingStation = false;
- // Site with Charging Station only
- const siteAreas = await SiteAreaStorage.getSiteAreas(tenant.id, { withChargingStations: true }, Constants.DB_PARAMS_MAX_LIMIT);
- if (siteAreas) {
- for (const siteArea of siteAreas.result) {
- if (siteArea.chargingStations) {
- for (const chargingStation of siteArea.chargingStations) {
- // Take into account this site?
- if (chargingStation.public) {
- foundPublicChargingStation = true;
ocpiLocationsResult.result.push(await OCPIMapping.convertSite2Location(tenant, site, options));
- break;
- }
- }
- }
- if (foundPublicChargingStation) {
- break;
- }
- }
- }
}
// Set count
- ocpiLocationsResult.count = ocpiLocationsResult.result.length;
+ ocpiLocationsResult.count = sites.count;
// Return locations
return ocpiLocationsResult;
}

MODIFY
src/server/rest/service/security/SiteSecurity.ts
src/server/rest/service/security/SiteSecurity.ts
@@ -105,6 +105,7 @@ export default class SiteSecurity {
filteredRequest.name = sanitize(request.name);
filteredRequest.address = UtilsSecurity.filterAddressRequest(request.address);
filteredRequest.image = sanitize(request.image);
+ filteredRequest.public = UtilsSecurity.filterBoolean(request.public);
filteredRequest.autoUserSiteAssignment =
UtilsSecurity.filterBoolean(request.autoUserSiteAssignment);
filteredRequest.companyID = sanitize(request.companyID);

MODIFY
src/storage/mongodb/SiteStorage.ts
src/storage/mongodb/SiteStorage.ts
@@ -259,6 +259,7 @@ export default class SiteStorage {
const siteMDB: any = {
_id: siteFilter._id,
issuer: Utils.convertToBoolean(siteToSave.issuer),
+ public: Utils.convertToBoolean(siteToSave.public),
companyID: Utils.convertToObjectID(siteToSave.companyID),
autoUserSiteAssignment: Utils.convertToBoolean(siteToSave.autoUserSiteAssignment),
name: siteToSave.name,
@@ -310,7 +311,7 @@ export default class SiteStorage {
public static async getSites(tenantID: string,
params: {
search?: string; companyIDs?: string[]; withAutoUserAssignment?: boolean; siteIDs?: string[];
- userID?: string; excludeSitesOfUserID?: boolean; issuer?: boolean;
+ userID?: string; excludeSitesOfUserID?: boolean; issuer?: boolean; onlyPublicSite?: boolean;
withAvailableChargingStations?: boolean; withOnlyChargingStations?: boolean; withCompany?: boolean;
locCoordinates?: number[]; locMaxDistanceMeters?: number;
} = {},
@@ -360,9 +361,14 @@ export default class SiteStorage {
$in: params.companyIDs.map((company) => Utils.convertToObjectID(company))
};
}
+ // Issuer
if (params.issuer === true || params.issuer === false) {
filters.issuer = params.issuer;
}
+ // Public Site
+ if (params.onlyPublicSite) {
+ filters.public = params.onlyPublicSite;
+ }
// Auto User Site Assignment
if (params.withAutoUserAssignment) {
filters.autoUserSiteAssignment = true;

MODIFY
src/types/Site.ts
src/types/Site.ts
@@ -16,6 +16,7 @@ export default interface Site extends CreatedUpdatedProps {
siteAreas?: SiteArea[];
company?: Company;
distanceMeters?: number;
+ public?: boolean;
}
export interface SiteUser {

Make Site public