@golemio/pid
Version:
Golemio PID Module
34 lines • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DetailedTripFacade = void 0;
const DetailedTripScopeEnum_1 = require("../../routers/v2/helpers/DetailedTripScopeEnum");
const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
class DetailedTripFacade {
constructor(scopeHandlerFactory, vehiclePositionRepository) {
this.scopeHandlerFactory = scopeHandlerFactory;
this.vehiclePositionRepository = vehiclePositionRepository;
}
async getOneByVehicleId(vehicleId, scopes, tripId) {
let vehiclePosition = await this.vehiclePositionRepository.getDetailedVehiclePosition(vehicleId);
if (tripId && vehiclePosition?.gtfs_trip_id !== tripId) {
vehiclePosition = await this.vehiclePositionRepository.getDetailedVehiclePosition(vehicleId, tripId);
}
if (!vehiclePosition) {
throw new golemio_errors_1.GeneralError("not_found", this.constructor.name, undefined, 404);
}
let output = {};
if (scopes.includes(DetailedTripScopeEnum_1.DetailedTripScope.Info)) {
output = await this.scopeHandlerFactory.getStrategy(DetailedTripScopeEnum_1.DetailedTripScope.Info).handle(output, vehiclePosition);
}
const promises = scopes.map(async (scope) => {
if (scope === DetailedTripScopeEnum_1.DetailedTripScope.Info) {
return;
}
output = await this.scopeHandlerFactory.getStrategy(scope).handle(output, vehiclePosition);
});
await Promise.all(promises);
return output;
}
}
exports.DetailedTripFacade = DetailedTripFacade;
//# sourceMappingURL=DetailedTripFacade.js.map