Simplify logic in createStationInfoHash() CS method
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 27 Apr 2022 15:55:33 +0000 (17:55 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 27 Apr 2022 15:55:33 +0000 (17:55 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts

index 690859e0ca4535cb35c7455a6b240574372f80b5..76a18e689e53f093657e7c86decb5b0328d935b5 100644 (file)
@@ -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;
   }