From: Jérôme Benoit Date: Mon, 27 Mar 2023 18:57:46 +0000 (+0200) Subject: fix: ensure charging profiles are deeply cloned before doing any X-Git-Tag: v1.2.0-2~6 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=66a62eacdeb0698d62a881ab41ca2d380b9a14f9;p=e-mobility-charging-stations-simulator.git fix: ensure charging profiles are deeply cloned before doing any treatment Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 1059a1d0..bcedfb3a 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -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)) {