Merge dependabot/npm_and_yarn/ui/web/jsdom-23.1.0 into combined-prs-branch
[e-mobility-charging-stations-simulator.git] / src / performance / storage / StorageFactory.ts
index 3da997257cc20c99e0ed3f5184abbe7db5583d55..f5cfcbefa6af6e134caef94f085f567170be40c6 100644 (file)
@@ -1,33 +1,40 @@
 // Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
 
-import { JsonFileStorage } from './JsonFileStorage';
-import { MikroOrmStorage } from './MikroOrmStorage';
-import { MongoDBStorage } from './MongoDBStorage';
-import type { Storage } from './Storage';
-import { StorageType } from '../../types/Storage';
+import { JsonFileStorage } from './JsonFileStorage.js'
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
+import { MikroOrmStorage } from './MikroOrmStorage.js'
+import { MongoDBStorage } from './MongoDBStorage.js'
+import type { Storage } from './Storage.js'
+import { BaseError } from '../../exception/index.js'
+import { StorageType } from '../../types/index.js'
 
+// eslint-disable-next-line @typescript-eslint/no-extraneous-class
 export class StorageFactory {
-  private constructor() {
+  private constructor () {
     // This is intentional
   }
 
-  public static getStorage(type: StorageType, connectionUri: string, logPrefix: string): Storage {
-    let storageInstance: Storage | null = null;
+  public static getStorage (
+    type: StorageType,
+    connectionUri: string,
+    logPrefix: string
+  ): Storage | undefined {
+    let storageInstance: Storage
     switch (type) {
       case StorageType.JSON_FILE:
-        storageInstance = new JsonFileStorage(connectionUri, logPrefix);
-        break;
+        storageInstance = new JsonFileStorage(connectionUri, logPrefix)
+        break
       case StorageType.MONGO_DB:
-        storageInstance = new MongoDBStorage(connectionUri, logPrefix);
-        break;
+        storageInstance = new MongoDBStorage(connectionUri, logPrefix)
+        break
       // case StorageType.MYSQL:
       // case StorageType.MARIA_DB:
       // case StorageType.SQLITE:
-      //   storageInstance = new MikroOrmStorage(connectionUri, logPrefix, type);
-      //   break;
+      //   storageInstance = new MikroOrmStorage(connectionUri, logPrefix, type)
+      //   break
       default:
-        throw new Error(`${logPrefix} Unknown storage type: ${type}`);
+        throw new BaseError(`${logPrefix} Unknown storage type: ${type}`)
     }
-    return storageInstance;
+    return storageInstance
   }
 }