fix: ensure charging profiles are deeply cloned before doing any
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 27 Mar 2023 18:57:46 +0000 (20:57 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 27 Mar 2023 18:57:46 +0000 (20:57 +0200)
treatment

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStationUtils.ts

index 1059a1d0c8b4da1215eb1184b1a25614ed32b07e..bcedfb3a3737311ba4426febfbe05656fd023cc1 100644 (file)
@@ -330,17 +330,16 @@ export class ChargingStationUtils {
   ): number | undefined {
     let limit: number, matchingChargingProfile: ChargingProfile;
     // Get charging profiles for connector and sort by stack level
-    const chargingProfiles = Utils.cloneObject(
-      chargingStation
-        .getConnectorStatus(connectorId)
-        ?.chargingProfiles?.sort((a, b) => b.stackLevel - a.stackLevel) ?? []
-    );
+    const chargingProfiles =
+      Utils.cloneObject(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles)?.sort(
+        (a, b) => b.stackLevel - a.stackLevel
+      ) ?? [];
     // Get profiles on connector 0
     if (chargingStation.getConnectorStatus(0)?.chargingProfiles) {
       chargingProfiles.push(
-        ...chargingStation
-          .getConnectorStatus(0)
-          .chargingProfiles.sort((a, b) => b.stackLevel - a.stackLevel)
+        ...Utils.cloneObject(chargingStation.getConnectorStatus(0).chargingProfiles).sort(
+          (a, b) => b.stackLevel - a.stackLevel
+        )
       );
     }
     if (Utils.isNotEmptyArray(chargingProfiles)) {