- public getReservationById(id: number): Reservation {
- return this.reservations?.find((reservation) => reservation.id === id);
- }
-
- public getReservationByIdTag(id: string): Reservation {
- return this.reservations?.find((reservation) => reservation.idTag === id);
- }
-
- public getReservationByConnectorId(id: number): Reservation {
- return this.reservations?.find((reservation) => reservation.connectorId === id);
- }
-
- public doesReservationExists(reservation: Partial<Reservation>): [boolean, Reservation] {
- const sameReservation = (r: Reservation) => r.id === reservation.id;
- const foundReservation = this.reservations?.find(sameReservation);
- return Utils.isUndefined(foundReservation) ? [false, null] : [true, foundReservation];
- }
-
- public async isAuthorized(
- connectorId: number,
- idTag: string,
- parentIdTag?: string
- ): Promise<boolean> {
- let authorized = false;
- const connectorStatus = this.getConnectorStatus(connectorId);
- if (
- this.getLocalAuthListEnabled() === true &&
- this.hasIdTags() === true &&
- Utils.isNotEmptyString(
- this.idTagsCache
- .getIdTags(ChargingStationUtils.getIdTagsFile(this.stationInfo))
- ?.find((tag) => tag === idTag)
- )
- ) {
- connectorStatus.localAuthorizeIdTag = idTag;
- connectorStatus.idTagLocalAuthorized = true;
- authorized = true;
- } else if (this.getMustAuthorizeAtRemoteStart() === true) {
- connectorStatus.authorizeIdTag = idTag;
- const authorizeResponse: OCPP16AuthorizeResponse =
- await this.ocppRequestService.requestHandler<
- OCPP16AuthorizeRequest,
- OCPP16AuthorizeResponse
- >(this, OCPP16RequestCommand.AUTHORIZE, {
- idTag: idTag,
- });
- if (authorizeResponse?.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
- authorized = true;
+ public getReservationBy(
+ filterKey: ReservationKey,
+ value: number | string,
+ ): Reservation | undefined {
+ if (this.hasEvses) {
+ for (const evseStatus of this.evses.values()) {
+ for (const connectorStatus of evseStatus.connectors.values()) {
+ if (connectorStatus?.reservation?.[filterKey] === value) {
+ return connectorStatus.reservation;
+ }
+ }