@golemio/pid
Version:
Golemio PID Module
61 lines • 2.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GTFSRoutesModel = void 0;
const const_1 = require("../../../schema-definitions/const");
const ropid_gtfs_1 = require("../../../schema-definitions/ropid-gtfs");
const RouteDto_1 = require("../../../schema-definitions/ropid-gtfs/models/RouteDto");
const output_gateway_1 = require("@golemio/core/dist/output-gateway");
const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
class GTFSRoutesModel extends output_gateway_1.SequelizeModel {
constructor() {
super(ropid_gtfs_1.RopidGTFS.routes.name, ropid_gtfs_1.RopidGTFS.routes.pgTableName, RouteDto_1.RouteDto.attributeModel, {
schema: const_1.PG_SCHEMA,
});
/** Retrieves all gtfs routes
* @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 } = options;
try {
const order = [];
order.push([["route_id", "asc"]]);
const data = await this.sequelizeModel.findAll({
limit,
offset,
order,
});
return data.map((item) => this.ConvertItem(item));
}
catch (err) {
throw new golemio_errors_1.GeneralError("Database error", "GTFSRoutesModel", err, 500);
}
};
/** Retrieves specific gtfs routes
* @param {string} id Id of the route
* @returns Object of the retrieved record or null
*/
this.GetOne = async (id) => this.ConvertItem(await this.sequelizeModel.findByPk(id));
/**
* Convert a single db result to proper output format with all tranformation
* @param {object} route Route object
* @returns A converted item of the result
*/
this.ConvertItem = (route) => {
if (route === null)
return null;
// fallback for not plain Sequelize object
if (route.toJSON)
route = route.toJSON();
// convert to booleans
route.is_night = route.is_night === "1";
route.is_regional = route.is_regional === "1";
route.is_substitute_transport = route.is_substitute_transport === "1";
return route;
};
}
}
exports.GTFSRoutesModel = GTFSRoutesModel;
//# sourceMappingURL=GTFSRoutesModel.js.map