clean up site areas + check for id
MODIFY
src/migration/MigrationHandler.ts
src/migration/MigrationHandler.ts
@@ -10,6 +10,7 @@ import AddTagTypeTask from './tasks/AddTagTypeTask';
import AddTransactionRefundStatusTask from './tasks/AddTransactionRefundStatusTask';
import CleanupMeterValuesTask from './tasks/CleanupMeterValuesTask';
import CleanupOrphanBadgeTask from './tasks/CleanupOrphanBadgeTask';
+import CleanupSiteAreasTask from './tasks/CleanupSiteAreasTask';
import Constants from '../utils/Constants';
import InitialCarImportTask from './tasks/InitialCarImportTask';
import { LockEntity } from '../types/Locking';
@@ -80,6 +81,7 @@ export default class MigrationHandler {
currentMigrationTasks.push(new AddConsumptionAmpsToConsumptionsTask());
currentMigrationTasks.push(new RecomputeAllTransactionsConsumptionsTask());
currentMigrationTasks.push(new RenameChargingStationPropertiesTask());
+ currentMigrationTasks.push(new CleanupSiteAreasTask());
// Get the already done migrations from the DB
const migrationTasksDone = await MigrationStorage.getMigrations();
// Check

ADD
src/migration/tasks/CleanupSiteAreasTask.ts
+import Constants from '../../utils/Constants';
+import Logging from '../../utils/Logging';
+import MigrationTask from '../MigrationTask';
+import { ServerAction } from '../../types/Server';
+import TenantStorage from '../../storage/mongodb/TenantStorage';
+import global from '../../types/GlobalType';
+
+const MODULE_NAME = 'CleanupSiteAreasTask';
+
+export default class CleanupSiteAreasTask extends MigrationTask {
+
+ async migrate() {
+ const tenants = await TenantStorage.getTenants({}, Constants.DB_PARAMS_MAX_LIMIT);
+ for (const tenant of tenants.result) {
+ await this.migrateTenant(tenant);
+ }
+ }
+
+ async migrateTenant(tenant) {
+ // Add Charging Station
+ const result = await global.database.getCollection<any>(tenant.id, 'siteareas').deleteMany({
+ 'name': null
+ });
+
+ // Log in the default tenant
+ if (result.deletedCount > 0) {
+ Logging.logDebug({
+ tenantID: Constants.DEFAULT_TENANT,
+ action: ServerAction.MIGRATION,
+ module: MODULE_NAME, method: 'migrateTenant',
+ message: `${result.deletedCount} Site area(s) have been deleted in Tenant '${tenant.name}'`
+ });
+ }
+ }
+
+ getVersion() {
+ return '1.0';
+ }
+
+ getName() {
+ return 'CleanupSiteAreasTask';
+ }
+
+ isAsynchronous() {
+ return true;
+ }
+}
+

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
@@ -760,9 +760,11 @@ export default class OCPPUtils {
consumption.limitSiteAreaSource = SiteAreaLimitSource.CHARGING_STATIONS;
// Save Site Area max consumption
siteArea.maximumPower = consumption.limitSiteAreaWatts;
+ if (siteArea.id) {
await SiteAreaStorage.saveSiteArea(tenantID, siteArea);
}
}
+ }
consumption.smartChargingActive = siteArea.smartCharging;
}

clean up site areas + check for id