Clean up user's data
MODIFY
src/migration/MigrationHandler.ts
src/migration/MigrationHandler.ts
@@ -14,6 +14,7 @@ import RestoreDataIntegrityInSiteUsersTask from './tasks/RestoreDataIntegrityInS
import { ServerAction } from '../types/Server';
import SimplePricingMigrationTask from './tasks/MigrateSimplePricing';
import UpdateEmailsToLowercaseTask from './tasks/UpdateEmailsToLowercaseTask';
+import UserCleanUpTask from './tasks/UserCleanUpTask';
import Utils from '../utils/Utils';
import moment from 'moment';
@@ -84,20 +85,6 @@ export default class MigrationHandler {
}
}
- private static createMigrationTasks(): MigrationTask[] {
- const currentMigrationTasks: MigrationTask[] = [];
- currentMigrationTasks.push(new RemoveDuplicateTagVisualIDsTask());
- currentMigrationTasks.push(new AddCompanyIDToTransactionsTask());
- currentMigrationTasks.push(new AddCompanyIDToChargingStationsTask());
- currentMigrationTasks.push(new RestoreDataIntegrityInSiteUsersTask());
- currentMigrationTasks.push(new AddUserIDToCarsTask());
- currentMigrationTasks.push(new RepairInvoiceInconsistencies());
- currentMigrationTasks.push(new SimplePricingMigrationTask());
- currentMigrationTasks.push(new RepairTransactionPricedAtZero());
- currentMigrationTasks.push(new UpdateEmailsToLowercaseTask());
- return currentMigrationTasks;
- }
-
private static async executeTask(currentMigrationTask: MigrationTask): Promise<void> {
try {
// Log Start Task
@@ -146,4 +133,19 @@ export default class MigrationHandler {
Logging.logConsoleError(logMsg);
}
}
+
+ private static createMigrationTasks(): MigrationTask[] {
+ const currentMigrationTasks: MigrationTask[] = [];
+ currentMigrationTasks.push(new RemoveDuplicateTagVisualIDsTask());
+ currentMigrationTasks.push(new AddCompanyIDToTransactionsTask());
+ currentMigrationTasks.push(new AddCompanyIDToChargingStationsTask());
+ currentMigrationTasks.push(new RestoreDataIntegrityInSiteUsersTask());
+ currentMigrationTasks.push(new AddUserIDToCarsTask());
+ currentMigrationTasks.push(new RepairInvoiceInconsistencies());
+ currentMigrationTasks.push(new SimplePricingMigrationTask());
+ currentMigrationTasks.push(new RepairTransactionPricedAtZero());
+ currentMigrationTasks.push(new UpdateEmailsToLowercaseTask());
+ currentMigrationTasks.push(new UserCleanUpTask());
+ return currentMigrationTasks;
+ }
}

ADD
src/migration/tasks/UserCleanUpTask.ts
+import Tenant from '../../types/Tenant';
+import TenantMigrationTask from '../TenantMigrationTask';
+import global from '../../types/GlobalType';
+
+export default class UserCleanUpTask extends TenantMigrationTask {
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
+ public async migrateTenant(tenant: Tenant) {
+ // Clean up
+ await global.database.getCollection(tenant.id, 'users').updateMany(
+ {}, { $unset: { lastSelectedCarID: '', lastSelectedCar: '' } });
+ }
+
+ public getVersion(): string {
+ return '1.0';
+ }
+
+ public getName(): string {
+ return 'UserCleanUpTask';
+ }
+
+ public isAsynchronous(): boolean {
+ return true;
+ }
+}

Clean up user's data