From: Jérôme Benoit Date: Sun, 30 Jul 2023 22:10:29 +0000 (+0200) Subject: refactor: cleanup reservation methods scope X-Git-Tag: v1.2.20~69 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e6948a57d6857b7b8667cbc8e707c0d79dafbc72;p=e-mobility-charging-stations-simulator.git refactor: cleanup reservation methods scope Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 7eef4100..1636f547 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -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; }