UNPKG

@golemio/parkings

Version:
80 lines 3.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Smart4CityLocationTransformation = void 0; const SourceEnum_1 = require("../../helpers/constants/SourceEnum"); const AbstractTransformation_1 = require("@golemio/core/dist/helpers/transformation/AbstractTransformation"); const output_gateway_1 = require("@golemio/core/dist/output-gateway"); const uuid_by_string_1 = __importDefault(require("uuid-by-string")); const getSmart4cityParkingType = (data) => { switch (data) { case 1: return "surface"; case 2: return "on_street"; default: return null; } }; class Smart4CityLocationTransformation extends AbstractTransformation_1.AbstractTransformation { constructor(code, transformationDate) { super(); this.code = code; this.transformationDate = transformationDate; this.name = "Smart4CityLocationTransformation"; this.transformInternal = (data) => { const location = { type: output_gateway_1.GeoCoordinatesType.Point, coordinates: [data.longitude, data.latitude], }; const uuid = (0, uuid_by_string_1.default)(SourceEnum_1.SourceEnum.Smart4City + data.id.toString()); const parking = { id: `${SourceEnum_1.SourceEnum.Smart4City}-${uuid}`, source: SourceEnum_1.SourceEnum.Smart4City, source_id: uuid, data_provider: `www.smart4city.cz-${this.code}`, name: data.name, location, centroid: location, total_spot_number: data.capacity !== 0 ? data.capacity : null, date_modified: this.transformationDate.toISOString(), valid_from: this.transformationDate.toISOString(), parking_type: getSmart4cityParkingType(data.type), active: true, }; return { ...parking, parkingLocation: this.transformLocation(parking), }; }; this.transformCollection = (data) => { const result = { parking: [], parkingLocation: [], }; for (const el of data) { if (!el.closed) { const { parkingLocation, ...parking } = this.transformElement(el); result.parking.push(parking); result.parkingLocation.push(parkingLocation); } } return result; }; this.transformLocation = (parking) => { return { id: parking.id, source: parking.source, source_id: parking.source_id, data_provider: parking.data_provider, location: parking.location, centroid: parking.centroid, total_spot_number: parking.total_spot_number, }; }; } } exports.Smart4CityLocationTransformation = Smart4CityLocationTransformation; //# sourceMappingURL=Smart4CityLocationTransformation.js.map