UNPKG

@golemio/parkings

Version:
129 lines • 6.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CachedParkingSourcesRepository = void 0; const _sch_1 = require("../../schema-definitions"); const ParkingSourcesModel_1 = require("../../schema-definitions/models/ParkingSourcesModel"); const AbstractCachedRepository_1 = require("@golemio/core/dist/helpers/data-access/postgres/repositories/AbstractCachedRepository"); const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors"); const sequelize_1 = require("@golemio/core/dist/shared/sequelize"); class CachedParkingSourcesRepository extends AbstractCachedRepository_1.AbstractCachedRepository { constructor(connector, log, cacheTTLInSeconds = 60 * 5) { super(connector, log, cacheTTLInSeconds); this.schema = _sch_1.Parkings.pgSchema; this.tableName = "parking_sources"; } async getV3Sources(options) { return (await this.getAllAllowed(options.isRestrictedToOpenData)) .filter((element) => element.api_v3_allowed) .map((element) => element.source); } async getLegacySources(options) { return (await this.getAllAllowed(options.isRestrictedToOpenData)) .filter((element) => element.legacy_api_allowed) .map((element) => element.source); } async getParkingSpaceDataSourceSources(options) { return (await this.getAllAllowed(options.isRestrictedToOpenData)) .filter((element) => element.datasource_parking && element.datasource_locations) .map((element) => element.source); } async getParkingPaymentDataSourceSources(options) { return (await this.getAllAllowed(options.isRestrictedToOpenData)) .filter((element) => element.datasource_payments) .map((element) => element.source); } async getEntrancesDataSourceSources(options) { return (await this.getAllAllowed(options.isRestrictedToOpenData)) .filter((element) => element.datasource_entrances) .map((element) => element.source); } async getProhibitionsDataSourceSources(options) { return (await this.getAllAllowed(options.isRestrictedToOpenData)) .filter((element) => element.datasource_prohibitions) .map((element) => element.source); } async getTariffsDataSourceSources(options) { return (await this.getAllAllowed(options.isRestrictedToOpenData)) .filter((element) => element.datasource_tariffs) .map((element) => element.source); } async getParkingMachinesDataSources(options) { return (await this.getAllAllowed(options.isRestrictedToOpenData)) .filter((element) => element.datasource_parking_machines) .map((element) => element.source); } async getParkingSpaceDataSourceConfig(options) { return (await this.getAllAllowed(options.isRestrictedToOpenData)) .filter((element) => element.datasource_parking && element.datasource_locations) .map((element) => ({ source: element.source, datasource_parking: element.datasource_parking, datasource_locations: element.datasource_locations, })); } async getParkingPaymentsDataSourceConfig(options) { return (await this.getAllAllowed(options.isRestrictedToOpenData)) .filter((element) => element.datasource_payments) .map((element) => ({ source: element.source, datasource_payments: element.datasource_payments, })); } async getParkingEntrancesDataSourceConfig(options) { return (await this.getAllAllowed(options.isRestrictedToOpenData)) .filter((element) => element.datasource_entrances) .map((element) => ({ source: element.source, datasource_entranecs: element.datasource_entrances, })); } async getParkingProhibitionsDataSourceConfig(options) { return (await this.getAllAllowed(options.isRestrictedToOpenData)) .filter((element) => element.datasource_prohibitions) .map((element) => ({ source: element.source, datasource_prohibitions: element.datasource_prohibitions, })); } async getParkingPaymentsConfig(options) { return (await this.getAllAllowed(options.isRestrictedToOpenData)).reduce((result, el) => { if (el.payment || el.reservation) { result[el.source] = { payment: el.payment, reservation: el.reservation, }; } return result; }, {}); } async getParkingTariffDataSourceConfig(options) { return (await this.getAllAllowed(options.isRestrictedToOpenData)) .filter((element) => element.datasource_tariffs) .map((element) => ({ source: element.source, datasource_tariffs: element.datasource_tariffs, })); } async getAllAllowed(isRestrictedToOpenData) { try { return (await this.getAll()).filter((element) => this.filterOpenData(element, isRestrictedToOpenData)); } catch (error) { if (error instanceof golemio_errors_1.AbstractGolemioError) { throw error; } throw new golemio_errors_1.GeneralError("Unable to load parking source table", CachedParkingSourcesRepository.name, error, 500); } } filterOpenData(source, isRestrictedToOpenData) { if (!isRestrictedToOpenData) return true; return source.open_data; } async getAllInternal() { return await this.connector.getConnection().query(`SELECT ${ParkingSourcesModel_1.ParkingSourcesModel.attributeList.join(",")} FROM ${this.schema}.${this.tableName}`, { type: sequelize_1.QueryTypes.SELECT, raw: true }); } } exports.CachedParkingSourcesRepository = CachedParkingSourcesRepository; //# sourceMappingURL=CachedParkingSourcesRepository.js.map