UNPKG

@golemio/pid

Version:
108 lines 5.21 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.StopFacade = void 0; const GtfsStopParser_1 = require("../../../../helpers/GtfsStopParser"); const OgPidToken_1 = require("../../ioc/OgPidToken"); const models_1 = require("../../../ropid-gtfs/models"); const CisStopGroupRepository_1 = require("../../../ropid-gtfs/data-access/CisStopGroupRepository"); const GtfsStopsRedisRepository_1 = require("../../../ropid-gtfs/data-access/redis/GtfsStopsRedisRepository"); const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe"); const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors"); let StopFacade = class StopFacade { constructor(cisStopGroupsRepository, gtfsStopsRedisRepository) { this.cisStopGroupsRepository = cisStopGroupsRepository; this.gtfsStopsRedisRepository = gtfsStopsRedisRepository; } async getStopIdsForTransferBoards(cisId) { //#region CIS stop node let aswNode; try { const cisStopNode = await this.cisStopGroupsRepository.getNodeByCisId(cisId); if (cisStopNode === null) { return []; } aswNode = cisStopNode; } catch (error) { if (error instanceof golemio_errors_1.AbstractGolemioError) { throw error; } throw new golemio_errors_1.GeneralError("Failed to retrieve CIS stop node", this.constructor.name, error, 500); } //#endregion //#region GTFS stop IDs let stopIds = []; try { stopIds = await models_1.models.GTFSStopModel.getMultipleIdsByAswNode(aswNode); } catch (error) { if (error instanceof golemio_errors_1.AbstractGolemioError) { throw error; } throw new golemio_errors_1.GeneralError("Failed to retrieve GTFS stops", this.constructor.name, error, 500); } //#endregion return stopIds; } /** * Retrieve ASW node ID for given CIS ID and then returns GTFS stop IDs for this ASW node */ async getStopIdsForTransferBoardsByCisId(cisId) { try { const aswNodeId = await this.gtfsStopsRedisRepository.getAswNodeIdFromCisId(cisId); if (aswNodeId === null) { return []; } return await this.getStopIdsForTransferBoardsByAswNode(aswNodeId); } catch (error) { if (error instanceof golemio_errors_1.AbstractGolemioError) throw error; throw new golemio_errors_1.GeneralError("Failed to retrieve CIS stop node", this.constructor.name, error, 500); } } /** * Retrieve ASW node ID for given ASW stop ID and then returns GTFS stop IDs for this ASW node */ async getStopIdsForTransferBoardsByAswId(aswId) { return await this.getStopIdsForTransferBoardsByAswNode(GtfsStopParser_1.GtfsStopParser.getAswNodeFromId(aswId)); } async getDetailDataFromCacheByStopId(stopId) { const aswIds = stopId.map((stopId) => GtfsStopParser_1.GtfsStopParser.normalizedStopId(stopId)); return this.getDetailDataFromCacheByAswId(aswIds); } async getDetailDataFromCacheByAswId(aswIds) { return await this.gtfsStopsRedisRepository.getGtfsStopsDetailsByAswId(aswIds); } async getStopIdsForTransferBoardsByAswNode(aswNodeId) { try { return await this.gtfsStopsRedisRepository.getGtfsStopIdsByAswNode(aswNodeId); } catch (error) { if (error instanceof golemio_errors_1.AbstractGolemioError) throw error; throw new golemio_errors_1.GeneralError("Failed to retrieve GTFS stops", this.constructor.name, error, 500); } } }; exports.StopFacade = StopFacade; exports.StopFacade = StopFacade = __decorate([ (0, tsyringe_1.injectable)(), __param(0, (0, tsyringe_1.inject)(OgPidToken_1.OgPidToken.CisStopGroupRepository)), __param(1, (0, tsyringe_1.inject)(OgPidToken_1.OgPidToken.GtfsStopsRedisRepository)), __metadata("design:paramtypes", [CisStopGroupRepository_1.CisStopGroupRepository, GtfsStopsRedisRepository_1.GtfsStopsRedisRepository]) ], StopFacade); //# sourceMappingURL=StopFacade.js.map