refactor: cleanup reservation methods scope
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 30 Jul 2023 22:10:29 +0000 (00:10 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 30 Jul 2023 22:10:29 +0000 (00:10 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts

index 7eef4100355d0113f23848f72bac8c26c9b38acc..1636f5470b42c58bf4c0d2e00476d19e1f489bc3 100644 (file)
@@ -1008,7 +1008,27 @@ export class ChargingStation {
     }
   }
 
-  public startReservationExpirationSetInterval(customInterval?: number): void {
+  public isConnectorReservable(
+    reservationId: number,
+    idTag?: string,
+    connectorId?: number,
+  ): boolean {
+    const reservationExists = !isUndefined(this.getReservationBy('reservationId', reservationId));
+    if (arguments.length === 1) {
+      return !reservationExists;
+    } else if (arguments.length > 1) {
+      const userReservationExists =
+        !isUndefined(idTag) && isUndefined(this.getReservationBy('idTag', idTag!)) ? false : true;
+      const notConnectorZero = isUndefined(connectorId) ? true : connectorId! > 0;
+      const freeConnectorsAvailable = this.getNumberOfReservableConnectors() > 0;
+      return (
+        !reservationExists && !userReservationExists && notConnectorZero && freeConnectorsAvailable
+      );
+    }
+    return false;
+  }
+
+  private startReservationExpirationSetInterval(customInterval?: number): void {
     const interval =
       customInterval ?? Constants.DEFAULT_RESERVATION_EXPIRATION_OBSERVATION_INTERVAL;
     if (interval > 0) {
@@ -1050,29 +1070,15 @@ export class ChargingStation {
     }
   }
 
-  public restartReservationExpiryDateSetInterval(): void {
-    this.stopReservationExpirationSetInterval();
-    this.startReservationExpirationSetInterval();
+  private stopReservationExpirationSetInterval(): void {
+    if (this.reservationExpirationSetInterval) {
+      clearInterval(this.reservationExpirationSetInterval);
+    }
   }
 
-  public isConnectorReservable(
-    reservationId: number,
-    idTag?: string,
-    connectorId?: number,
-  ): boolean {
-    const reservationExists = !isUndefined(this.getReservationBy('reservationId', reservationId));
-    if (arguments.length === 1) {
-      return !reservationExists;
-    } else if (arguments.length > 1) {
-      const userReservationExists =
-        !isUndefined(idTag) && isUndefined(this.getReservationBy('idTag', idTag!)) ? false : true;
-      const notConnectorZero = isUndefined(connectorId) ? true : connectorId! > 0;
-      const freeConnectorsAvailable = this.getNumberOfReservableConnectors() > 0;
-      return (
-        !reservationExists && !userReservationExists && notConnectorZero && freeConnectorsAvailable
-      );
-    }
-    return false;
+  private restartReservationExpiryDateSetInterval(): void {
+    this.stopReservationExpirationSetInterval();
+    this.startReservationExpirationSetInterval();
   }
 
   private getNumberOfReservableConnectors(): number {
@@ -1126,12 +1132,6 @@ export class ChargingStation {
     return this.stationInfo.supervisionUrlOcppConfiguration ?? false;
   }
 
-  private stopReservationExpirationSetInterval(): void {
-    if (this.reservationExpirationSetInterval) {
-      clearInterval(this.reservationExpirationSetInterval);
-    }
-  }
-
   private getSupervisionUrlOcppKey(): string {
     return this.stationInfo.supervisionUrlOcppKey ?? VendorParametersKey.ConnectionUrl;
   }