UNPKG

@golemio/pid

Version:
39 lines 1.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GtfsTripLookupFacade = void 0; const DetailedTripScopeEnum_1 = require("../../routers/v2/helpers/DetailedTripScopeEnum"); const models_1 = require("../../../ropid-gtfs/models"); const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors"); class GtfsTripLookupFacade { constructor(scopeHandlerFactory) { this.scopeHandlerFactory = scopeHandlerFactory; this.gtfsTripRepository = models_1.models.GTFSTripsModel; } async getOneByGtfsTripId(gtfsTripId, scopes) { const shouldIncludeStopTimes = scopes.includes(DetailedTripScopeEnum_1.DetailedTripScope.StopTimes); const shouldIncludeShapes = scopes.includes(DetailedTripScopeEnum_1.DetailedTripScope.Shapes); const gtfsTrip = await this.gtfsTripRepository.getOneForPublicGtfsLookup(gtfsTripId, { shouldIncludeStopTimes, shouldIncludeShapes, }); if (!this.isGtfsTripValid(gtfsTrip)) { throw new golemio_errors_1.GeneralError("GTFS trip info not found", this.constructor.name, undefined, 404); } let output = {}; if (scopes.includes(DetailedTripScopeEnum_1.DetailedTripScope.Info)) { output = this.scopeHandlerFactory.getStrategy(DetailedTripScopeEnum_1.DetailedTripScope.Info).handle(output, gtfsTrip); } for (const scope of scopes) { if (scope === DetailedTripScopeEnum_1.DetailedTripScope.Info) { continue; } output = this.scopeHandlerFactory.getStrategy(scope).handle(output, gtfsTrip); } return output; } isGtfsTripValid(gtfsTrip) { return !!gtfsTrip && !!gtfsTrip.route; } } exports.GtfsTripLookupFacade = GtfsTripLookupFacade; //# sourceMappingURL=GtfsTripLookupFacade.js.map