Refine connector id validation error message
[e-mobility-charging-stations-simulator.git] / src / performance / storage / JsonFileStorage.ts
index 17f5ad2f62ff92f3b06b7abb7b068208a62a325e..8465290325173d316a24e6ef26f1d6a252675ad1 100644 (file)
@@ -1,11 +1,14 @@
 // Copyright Jerome Benoit. 2021. All Rights Reserved.
 
+import fs from 'fs';
+
+import lockfile from 'proper-lockfile';
+
 import { FileType } from '../../types/FileType';
+import type { Statistics } from '../../types/Statistics';
 import FileUtils from '../../utils/FileUtils';
-import Statistics from '../../types/Statistics';
+import Utils from '../../utils/Utils';
 import { Storage } from './Storage';
-import fs from 'fs';
-import lockfile from 'proper-lockfile';
 
 export class JsonFileStorage extends Storage {
   private fd: number | null = null;
@@ -28,19 +31,7 @@ export class JsonFileStorage extends Storage {
           performanceRecords.push(performanceStatistics);
           fs.writeFileSync(
             this.dbName,
-            JSON.stringify(
-              performanceRecords,
-              (key, value) => {
-                if (value instanceof Map) {
-                  return {
-                    dataType: 'Map',
-                    value: [...value],
-                  };
-                }
-                return value as Statistics;
-              },
-              2
-            ),
+            Utils.JSONStringifyWithMapSupport(performanceRecords, 2),
             'utf8'
           );
         } catch (error) {