fixed handling of siteID in site area rest endpoint
MODIFY
src/server/rest/v1/service/SiteAreaService.ts
src/server/rest/v1/service/SiteAreaService.ts
@@ -195,7 +195,7 @@ export default class SiteAreaService {
}
// Save
if (action === ServerAction.ADD_CHARGING_STATIONS_TO_SITE_AREA) {
- await SiteAreaStorage.addChargingStationsToSiteArea(req.user.tenantID, filteredRequest.siteAreaID, filteredRequest.chargingStationIDs);
+ await SiteAreaStorage.addChargingStationsToSiteArea(req.user.tenantID, siteArea, filteredRequest.chargingStationIDs);
} else {
await SiteAreaStorage.removeChargingStationsFromSiteArea(req.user.tenantID, filteredRequest.siteAreaID, filteredRequest.chargingStationIDs);
}

MODIFY
src/storage/mongodb/SiteAreaStorage.ts
src/storage/mongodb/SiteAreaStorage.ts
@@ -311,20 +311,23 @@ export default class SiteAreaStorage {
};
}
- public static async addChargingStationsToSiteArea(tenantID: string, siteAreaID: string, chargingStationIDs: string[]): Promise<void> {
+ public static async addChargingStationsToSiteArea(tenantID: string, siteArea: SiteArea, chargingStationIDs: string[]): Promise<void> {
// Debug
const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'addChargingStationsToSiteArea');
// Check Tenant
await DatabaseUtils.checkTenant(tenantID);
// Site provided?
- if (siteAreaID) {
+ if (siteArea) {
// At least one ChargingStation
if (chargingStationIDs && chargingStationIDs.length > 0) {
// Update all chargers
await global.database.getCollection<any>(tenantID, 'chargingstations').updateMany(
{ '_id': { $in: chargingStationIDs } },
{
- $set: { siteAreaID: Utils.convertToObjectID(siteAreaID) }
+ $set: {
+ siteAreaID: Utils.convertToObjectID(siteArea.id),
+ siteID: Utils.convertToObjectID(siteArea.siteID)
+ }
});
}
}
@@ -345,7 +348,10 @@ export default class SiteAreaStorage {
await global.database.getCollection<any>(tenantID, 'chargingstations').updateMany(
{ '_id': { $in: chargingStationIDs } },
{
- $set: { siteAreaID: null }
+ $set: {
+ siteAreaID: null,
+ siteID: null
+ }
});
}
}

fixed handling of siteID in site area rest endpoint