From d2cd59f04ae667c1671ba5566307fe0e8e3e4352 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 30 Jul 2023 18:16:35 +0200 Subject: [PATCH] fix: handle proper the number of arguments in isConnectorReservable() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index ccc95263..bf5bc189 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -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 { -- 2.34.1