feat(simulator): add certificates related OCPP 2.x types
[e-mobility-charging-stations-simulator.git] / src / performance / storage / MikroOrmStorage.ts
index 1953491adb698692172c7595ac57e28016cc7360..47823c8052d94800f779f85bfe2e182c12f62396 100644 (file)
@@ -1,18 +1,21 @@
-// Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
 
 import { Configuration, Connection, IDatabaseDriver, MikroORM, Options } from '@mikro-orm/core';
-import { MikroORMDBType, StorageType } from '../../types/Storage';
-
-import Constants from '../../utils/Constants';
-import { PerformanceData } from '../../types/orm/entities/PerformanceData';
-import { PerformanceRecord } from '../../types/orm/entities/PerformanceRecord';
-import Statistics from '../../types/Statistics';
-import { Storage } from './Storage';
 import { TsMorphMetadataProvider } from '@mikro-orm/reflection';
 
+import {
+  type MikroORMDBType,
+  PerformanceData,
+  PerformanceRecord,
+  type Statistics,
+  StorageType,
+} from '../../types';
+import { Constants } from '../../utils';
+import { Storage } from '../internal';
+
 export class MikroOrmStorage extends Storage {
   private storageType: StorageType;
-  private orm: MikroORM | null;
+  private orm!: MikroORM | null;
 
   constructor(storageUri: string, logPrefix: string, storageType: StorageType) {
     super(storageUri, logPrefix);
@@ -23,7 +26,7 @@ export class MikroOrmStorage extends Storage {
   public async storePerformanceStatistics(performanceStatistics: Statistics): Promise<void> {
     try {
       const performanceRecord = new PerformanceRecord();
-      await this.orm.em.persistAndFlush(performanceRecord);
+      await this.orm?.em.persistAndFlush(performanceRecord);
     } catch (error) {
       this.handleDBError(this.storageType, error as Error, Constants.PERFORMANCE_RECORDS_TABLE);
     }
@@ -71,7 +74,7 @@ export class MikroOrmStorage extends Storage {
     };
   }
 
-  private getClientUrl(): string {
+  private getClientUrl(): string | undefined {
     switch (this.storageType) {
       case StorageType.SQLITE:
       case StorageType.MARIA_DB: