From: Jérôme Benoit Date: Wed, 27 Apr 2022 15:55:33 +0000 (+0200) Subject: Simplify logic in createStationInfoHash() CS method X-Git-Tag: v1.1.59~19 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3ead11bafea04b49a11a4a3fe9a0e19750c952fa;p=e-mobility-charging-stations-simulator.git Simplify logic in createStationInfoHash() CS method Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 690859e0..76a18e68 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -960,7 +960,7 @@ export default class ChargingStation { private getStationInfoFromTemplate(): ChargingStationInfo { const stationInfo: ChargingStationInfo = this.getTemplateFromFile(); if (Utils.isNullOrUndefined(stationInfo)) { - const logMsg = 'Fail to read charging station template file'; + const logMsg = 'Failed to read charging station template file'; logger.error(`${this.logPrefix()} ${logMsg}`); throw new BaseError(logMsg); } @@ -1001,19 +1001,21 @@ export default class ChargingStation { } private createStationInfoHash(stationInfo: ChargingStationInfo): ChargingStationInfo { - const previousInfoHash = stationInfo?.infoHash ?? ''; - delete stationInfo.infoHash; - const currentInfoHash = crypto - .createHash(Constants.DEFAULT_HASH_ALGORITHM) - .update(JSON.stringify(stationInfo)) - .digest('hex'); - if ( - (!Utils.isEmptyObject(stationInfo) && Utils.isEmptyString(previousInfoHash)) || - (!Utils.isEmptyString(previousInfoHash) && currentInfoHash !== previousInfoHash) - ) { - stationInfo.infoHash = currentInfoHash; - } else if (!Utils.isEmptyObject(stationInfo)) { - stationInfo.infoHash = previousInfoHash; + if (!Utils.isEmptyObject(stationInfo)) { + const previousInfoHash = stationInfo?.infoHash ?? ''; + delete stationInfo.infoHash; + const currentInfoHash = crypto + .createHash(Constants.DEFAULT_HASH_ALGORITHM) + .update(JSON.stringify(stationInfo)) + .digest('hex'); + if ( + Utils.isEmptyString(previousInfoHash) || + (!Utils.isEmptyString(previousInfoHash) && currentInfoHash !== previousInfoHash) + ) { + stationInfo.infoHash = currentInfoHash; + } else { + stationInfo.infoHash = previousInfoHash; + } } return stationInfo; }