UNPKG

@golemio/parkings

Version:
55 lines 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.V2ParkingTariffsRepository = void 0; const ParkingTariffsModel_1 = require("../../../schema-definitions/models/ParkingTariffsModel"); const output_gateway_1 = require("@golemio/core/dist/output-gateway"); const index_1 = require("../../../schema-definitions/index"); const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors"); const sequelize_1 = require("@golemio/core/dist/shared/sequelize"); class V2ParkingTariffsRepository extends output_gateway_1.SequelizeModel { constructor(parkingSourcesRepository) { super("V2TariffRepository", ParkingTariffsModel_1.ParkingTariffsModel.tableName, ParkingTariffsModel_1.ParkingTariffsModel.attributeModel, { schema: index_1.Parkings.pgSchema, }); this.parkingSourcesRepository = parkingSourcesRepository; this.GetAll = async (options = {}) => { const { source } = options; let where = {}; let attributes = { include: [], exclude: [] }; if (source) { where.source = source; } else { where.source = { [sequelize_1.Op.in]: await this.parkingSourcesRepository.getLegacySources({ isRestrictedToOpenData: false }), }; } const order = []; order.push(["tariff_id", "asc"], ["charge_order_index", "asc"]); try { return await this.sequelizeModel.findAll({ attributes, order, raw: true, where, }); } catch (err) { throw new golemio_errors_1.GeneralError("Database error", "ParkingTariffsModel", err, 500); } }; this.GetOne = async (tariffId) => { return await this.sequelizeModel.findAll({ where: { tariff_id: tariffId, source: { [sequelize_1.Op.in]: await this.parkingSourcesRepository.getLegacySources({ isRestrictedToOpenData: false }), }, }, raw: true, }); }; } } exports.V2ParkingTariffsRepository = V2ParkingTariffsRepository; //# sourceMappingURL=V2ParkingTariffsRepository.js.map