UNPKG

@golemio/pid

Version:
44 lines 2.35 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GtfsStopParser = void 0; const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors"); const sequelize_1 = require("@golemio/core/dist/shared/sequelize"); const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe"); const const_1 = require("../const"); let GtfsStopParser = exports.GtfsStopParser = class GtfsStopParser { prepareAswWhereOptions(aswIds) { let aswWhereOptions = []; for (const aswId of aswIds) { let aswIdLike = aswId.replaceAll("_", "/"); if (aswIdLike.slice(-1) === "/") { aswIdLike = aswIdLike.slice(0, -1); } const [nodeId, stopId] = aswIdLike.split("/"); if (!nodeId) { continue; } this.validateAswId(aswId, nodeId, stopId); aswWhereOptions.push(sequelize_1.Sequelize.and(sequelize_1.Sequelize.where(sequelize_1.Sequelize.col("asw_node_id"), "=", nodeId), stopId && sequelize_1.Sequelize.where(sequelize_1.Sequelize.col("asw_stop_id"), "=", stopId))); } return aswWhereOptions; } isValidInteger(value) { return value >= const_1.PG_INT_MIN && value <= const_1.PG_INT_MAX; } validateAswId(aswId, nodeId, stopId) { const nodeIdNum = Number(nodeId); if (!this.isValidInteger(nodeIdNum) || (stopId && !this.isValidInteger(Number(stopId)))) { throw new golemio_errors_1.GeneralError(`Invalid ASW ID: ${aswId}`, this.constructor.name, `Invalid ASW ID: ${aswId}`, 400); } } }; exports.GtfsStopParser = GtfsStopParser = __decorate([ (0, tsyringe_1.injectable)() ], GtfsStopParser); //# sourceMappingURL=GtfsStopParser.js.map