From: Jérôme Benoit Date: Fri, 12 May 2023 13:50:53 +0000 (+0200) Subject: refactor: factor out performance records JSON file path building X-Git-Tag: v1.2.14~60 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e8044a69a745aab08dfeea0bd9ec9dd7fe84cdd7;p=e-mobility-charging-stations-simulator.git refactor: factor out performance records JSON file path building Signed-off-by: Jérôme Benoit --- diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index cf4d2bca..6423e34c 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -94,10 +94,9 @@ export class Configuration { ...Configuration.getConfig()?.performanceStorage, ...(Configuration.getConfig()?.performanceStorage?.type === StorageType.JSON_FILE && Configuration.getConfig()?.performanceStorage?.uri && { - uri: `file://${path.join( - path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'), + uri: Configuration.buildPerformanceUriFilePath( new URL(Configuration.getConfig()?.performanceStorage?.uri).pathname - )}`, + ), }), }; } @@ -393,17 +392,22 @@ export class Configuration { private static getDefaultPerformanceStorageUri(storageType: StorageType) { switch (storageType) { case StorageType.JSON_FILE: - return `file://${path.join( - path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'), + return Configuration.buildPerformanceUriFilePath( Constants.DEFAULT_PERFORMANCE_RECORDS_FILENAME - )}`; + ); case StorageType.SQLITE: - return `file://${path.join( - path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'), + return Configuration.buildPerformanceUriFilePath( `${Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME}.db` - )}`; + ); default: throw new Error(`Performance storage URI is mandatory with storage type '${storageType}'`); } } + + private static buildPerformanceUriFilePath(file: string) { + return `file://${path.join( + path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'), + file + )}`; + } }