@golemio/pid
Version:
Golemio PID Module
53 lines • 2.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GTFSShapesModel = void 0;
const const_1 = require("../../../schema-definitions/const");
const ropid_gtfs_1 = require("../../../schema-definitions/ropid-gtfs");
const ShapeDto_1 = require("../../../schema-definitions/ropid-gtfs/models/ShapeDto");
const output_gateway_1 = require("@golemio/core/dist/output-gateway");
const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
class GTFSShapesModel extends output_gateway_1.SequelizeModel {
constructor() {
super(ropid_gtfs_1.RopidGTFS.shapes.name, ropid_gtfs_1.RopidGTFS.shapes.pgTableName, ShapeDto_1.ShapeDto.attributeModel, {
schema: const_1.PG_SCHEMA,
});
this.outputAttributes = [];
this.Associate = (models) => {
this.sequelizeModel.hasMany(models.GTFSTripsModel.sequelizeModel, {
foreignKey: "trip_id",
});
};
/** Retrieves all gtfs shapes
* @param {object} [options] Options object with params
* @param {number} [options.limit] Limit
* @param {number} [options.offset] Offset
* @returns Array of the retrieved records
*/
this.GetAll = async (options = {}) => {
const { limit, offset, id } = options;
try {
const order = [];
order.push([["shape_id", "asc"]]);
const data = await this.sequelizeModel.findAll({
limit,
offset,
order,
where: { shape_id: id },
});
if (data.length === 0) {
return;
}
return (0, output_gateway_1.buildGeojsonFeatureCollection)(data, "shape_pt_lon", "shape_pt_lat", true);
}
catch (err) {
throw new golemio_errors_1.GeneralError("Database error ~ GetAll", "GTFSShapesModel", err, 500);
}
};
this.GetOne = async (id) => {
return null;
};
this.outputAttributes = Object.keys(ShapeDto_1.ShapeDto.attributeModel);
}
}
exports.GTFSShapesModel = GTFSShapesModel;
//# sourceMappingURL=GTFSShapesModel.js.map