fix: handle proper the number of arguments in isConnectorReservable()
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 30 Jul 2023 16:16:35 +0000 (18:16 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 30 Jul 2023 16:16:35 +0000 (18:16 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts

index ccc9526369c24ceae553ed2f702b310be654c7b6..bf5bc189d4d3ad22eacd853fa621229b44013e74 100644 (file)
@@ -1065,13 +1065,18 @@ export class ChargingStation {
     connectorId?: number,
   ): boolean {
     const reservationExists = !isUndefined(this.getReservationBy('reservationId', reservationId));
-    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
-    );
+    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 getNumberOfReservableConnectors(): number {