UNPKG

@golemio/parkings

Version:
72 lines 4.01 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.IptOictTariffsTransformation = void 0; const AbstractTransformation_1 = require("@golemio/core/dist/helpers/transformation/AbstractTransformation"); const uuid_by_string_1 = __importDefault(require("uuid-by-string")); class IptOictTariffsTransformation extends AbstractTransformation_1.AbstractTransformation { constructor(source, transformationDate) { super(); this.source = source; this.transformationDate = transformationDate; this.name = "IptOictTariffsTransformation"; this.transformInternal = (element) => { const tariffs = []; for (const chargeBands of element.charge_bands) { const bandCommon = { source: this.source, maximum_duration_seconds: chargeBands.maximum_duration, valid_from: chargeBands.valid_from ? new Date(chargeBands.valid_from) : null, valid_to: chargeBands.valid_to ? new Date(chargeBands.valid_to) : null, last_updated: chargeBands.last_modified_at_source ? new Date(chargeBands.last_modified_at_source) : this.transformationDate, free_of_charge: chargeBands.free_of_charge, url_link_address: chargeBands.url, payment_mode: chargeBands.payment_mode, payment_methods: chargeBands.payment_methods, charge_band_name: chargeBands.charge_band_name, accepts_payment_card: chargeBands.payment_methods.includes("card_offline"), accepts_cash: chargeBands.payment_methods.includes("cash"), accepts_mobile_payment: chargeBands.payment_methods.includes("mobile_app"), accepts_litacka: chargeBands.payment_methods.includes("litacka"), }; for (const charge of chargeBands.charges) { const chargeItem = { charge: parseInt(charge.charge), charge_currency: "czk", charge_type: charge.charge_type, charge_order_index: charge.charge_order_index, charge_interval: charge.charge_interval, max_iterations_of_charge: charge.max_iterations_of_charge, min_iterations_of_charge: charge.min_iterations_of_charge, valid_from: charge.valid_from ? new Date(charge.valid_from) : null, valid_to: charge.valid_to ? new Date(charge.valid_to) : null, periods_of_time: charge.periods_of_time, }; const tariffId = (0, uuid_by_string_1.default)(`${this.source}`.toUpperCase() + `${JSON.stringify(element.parking_ids)}`); tariffs.push({ ...bandCommon, ...chargeItem, tariff_id: tariffId }); } } return tariffs; }; this.transformParkingTariffsRelation = (source, data) => { const parkingTariffsIdPairs = []; for (const item of data) { const tariffId = (0, uuid_by_string_1.default)(`${this.source}`.toUpperCase() + `${JSON.stringify(item.parking_ids)}`); for (const id of item.parking_ids) { parkingTariffsIdPairs.push({ parking_id: `${this.source}-${id}`, tariff_id: tariffId, source, }); } } return parkingTariffsIdPairs; }; } } exports.IptOictTariffsTransformation = IptOictTariffsTransformation; //# sourceMappingURL=IptOictTariffsTransformation.js.map