@golemio/parkings
Version:
Golemio Parkings Module
140 lines • 6.67 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.KoridParkingConfigTransformation = void 0;
const _sch_1 = require("../../schema-definitions");
const integration_engine_1 = require("@golemio/core/dist/integration-engine");
const turf = __importStar(require("@turf/turf"));
const uuid_by_string_1 = __importDefault(require("uuid-by-string"));
class KoridParkingConfigTransformation extends integration_engine_1.BaseTransformation {
constructor() {
super();
this.transform = async (data) => {
const geoResults = [];
const tariffResults = [];
const parkingTariffsRelationsResults = [];
const locationResults = [];
const dateModified = new Date(data.time).toISOString();
for (const element of data.geojson.features) {
geoResults.push(await this.transformElement({
...element,
time: dateModified,
}));
locationResults.push(this.transformLocation({
...element,
time: dateModified,
}));
parkingTariffsRelationsResults.push(this.transformParkingTariffsRelation(element));
}
tariffResults.push(...this.transformTariffElement(data.tarif));
return {
geo: geoResults,
tariff: tariffResults,
location: locationResults,
parkingTariffsRelations: parkingTariffsRelationsResults,
};
};
this.transformElement = async (element) => {
return {
id: `${this.dataSource}-${element.properties.groupid}`.toLowerCase(),
data_provider: "www.korid.cz",
date_modified: element.time,
location: element.geometry,
name: element.properties.title,
source: this.dataSource,
source_id: "" + element.properties.groupid,
total_spot_number: element.properties.total,
parking_type: "on_street",
zone_type: null,
centroid: turf.centroid(element.geometry).geometry,
active: true,
};
};
this.transformParkingTariffsRelation = (element) => {
return {
source: this.dataSource,
parking_id: `${this.dataSource}-${element.properties.groupid}`.toLowerCase(),
tariff_id: (0, uuid_by_string_1.default)(this.dataSource + element.properties.tarif),
};
};
this.transformLocation = (element) => {
return {
id: `${this.dataSource}-${element.properties.groupid}`.toLowerCase(),
data_provider: "www.korid.cz",
location: element.geometry,
centroid: turf.centroid(element.geometry).geometry,
total_spot_number: element.properties.total,
source: this.dataSource,
source_id: "" + element.properties.groupid,
};
};
this.transformMeansOfPayments = (data) => ({
accepts_payment_card: data.includes("paymentCard"),
accepts_cash: data.includes("cash"),
});
this.transformTariffElement = (element) => {
const tariff = [];
const tariffDescription = {
source: this.dataSource,
last_updated: element.lastUpdated,
payment_mode: element.paymentMode.join(","),
payment_additional_description: element.paymentAdditionalDescription,
free_of_charge: element.freeOfCharge,
url_link_address: element.urlLinkAddress,
};
for (const chargeBandElement of element.chargeBand) {
const chargeDescription = {
tariff_id: (0, uuid_by_string_1.default)(this.dataSource + chargeBandElement.chargeBandName),
charge_band_name: chargeBandElement.chargeBandName,
charge_currency: chargeBandElement.chargeCurrency,
...this.transformMeansOfPayments(chargeBandElement.acceptedMeansOfPayment || []),
};
for (const chargeElement of chargeBandElement.charge) {
let timePeriod = chargeElement.timePeriod ? chargeElement.timePeriod : {};
tariff.push({
...tariffDescription,
...chargeDescription,
charge: chargeElement.charge,
charge_type: chargeElement.chargeType,
charge_order_index: chargeElement.chargeOrderIndex,
charge_interval: chargeElement.chargeInterval,
max_iterations_of_charge: chargeElement.maxIterationsOfCharge,
min_iterations_of_charge: chargeElement.minIterationsOfCharge,
start_time_of_period: timePeriod.startTimeOfPeriod,
end_time_of_period: timePeriod.endTimeOfPeriod,
});
}
}
return tariff;
};
this.name = _sch_1.Parkings.korid.name + "Config";
this.dataSource = "korid";
}
}
exports.KoridParkingConfigTransformation = KoridParkingConfigTransformation;
//# sourceMappingURL=KoridParkingConfigTransformation.js.map