refactor(simulator): remove unused async lock class attribute
[e-mobility-charging-stations-simulator.git] / src / performance / storage / MikroOrmStorage.ts
index f9c21290596b660bdecc1308c3a3fc079befbcd3..e5b09b588b2a373ea14aa76854f9a3e5fc1df7f5 100644 (file)
@@ -1,18 +1,27 @@
 // Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
 
-import { Configuration, Connection, IDatabaseDriver, MikroORM, Options } from '@mikro-orm/core';
+import {
+  Configuration,
+  Connection,
+  type IDatabaseDriver,
+  MikroORM,
+  type Options,
+} from '@mikro-orm/core';
 import { TsMorphMetadataProvider } from '@mikro-orm/reflection';
 
-import { PerformanceData } from '../../types/orm/entities/PerformanceData';
-import { PerformanceRecord } from '../../types/orm/entities/PerformanceRecord';
-import type { Statistics } from '../../types/Statistics';
-import { MikroORMDBType, StorageType } from '../../types/Storage';
-import Constants from '../../utils/Constants';
 import { Storage } from './Storage';
+import {
+  type MikroOrmDbType,
+  PerformanceData,
+  PerformanceRecord,
+  type Statistics,
+  StorageType,
+} from '../../types';
+import { Constants } from '../../utils';
 
 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 +32,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);
     }
@@ -66,12 +75,12 @@ export class MikroOrmStorage extends Storage {
     return {
       metadataProvider: TsMorphMetadataProvider,
       entities: [PerformanceRecord, PerformanceData],
-      type: this.storageType as MikroORMDBType,
+      type: this.storageType as MikroOrmDbType,
       clientUrl: this.getClientUrl(),
     };
   }
 
-  private getClientUrl(): string {
+  private getClientUrl(): string | undefined {
     switch (this.storageType) {
       case StorageType.SQLITE:
       case StorageType.MARIA_DB: