@golemio/parkings
Version:
Golemio Parkings Module
91 lines • 4.42 kB
JavaScript
;
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Smart4CityParkingTransformation = void 0;
const AbstractTransformation_1 = require("@golemio/core/dist/helpers/transformation/AbstractTransformation");
const turf = __importStar(require("@turf/turf"));
class Smart4CityParkingTransformation extends AbstractTransformation_1.AbstractTransformation {
constructor(source, transformationDate, smart4CityRoleHelper) {
super();
this.source = source;
this.transformationDate = transformationDate;
this.smart4CityRoleHelper = smart4CityRoleHelper;
this.name = "Smart4CityParkingTransformation";
this.transformInternal = (element) => {
const transformed = [];
const transformadSpaces = [];
const dataProvider = "www.smart4city.cz";
for (const parkingLocation of element.data.parking_locations) {
const parkingId = `${this.source}-${parkingLocation.code}`;
transformed.push({
id: parkingId,
source: this.source,
source_id: parkingLocation.code,
data_provider: dataProvider,
location: parkingLocation.definition,
name: parkingLocation.name,
valid_from: this.transformationDate.toISOString(),
date_modified: parkingLocation.last_changes,
total_spot_number: parkingLocation.capacity,
parking_type: null,
active: true,
centroid: turf.centroid(parkingLocation.definition).geometry,
});
if (parkingLocation._places.length > 0) {
for (const parkingSpace of parkingLocation._places) {
transformadSpaces.push({
id: `${this.source}-${parkingSpace.id}`,
source: this.source,
source_id: parkingLocation.code,
data_provider: dataProvider,
location: parkingSpace.coords,
total_spot_number: 1,
special_access: this.getSpecialFeatures(parkingSpace.actualRoleID.$oid),
centroid: turf.centroid(parkingSpace.coords).geometry,
});
}
}
else {
transformadSpaces.push({
id: `${parkingId}-1`,
source: this.source,
source_id: parkingLocation.code,
data_provider: dataProvider,
location: parkingLocation.definition,
total_spot_number: parkingLocation.capacity,
centroid: turf.centroid(parkingLocation.definition).geometry,
});
}
}
return { parking: transformed, spaces: transformadSpaces };
};
}
getSpecialFeatures(roleId) {
const access = this.smart4CityRoleHelper.getAccess(roleId);
return access ? [access] : undefined;
}
}
exports.Smart4CityParkingTransformation = Smart4CityParkingTransformation;
//# sourceMappingURL=Smart4CityParkingTransformation.js.map