From: Jérôme Benoit Date: Sun, 30 Jul 2023 16:16:35 +0000 (+0200) Subject: fix: handle proper the number of arguments in isConnectorReservable() X-Git-Tag: v1.2.20~80 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=d2cd59f04ae667c1671ba5566307fe0e8e3e4352;p=e-mobility-charging-stations-simulator.git fix: handle proper the number of arguments in isConnectorReservable() Signed-off-by: Jérôme Benoit --- 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 {