@golemio/parkings
Version:
Golemio Parkings Module
38 lines • 1.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GreenCenterMeasurementTransformation = void 0;
const SourceEnum_1 = require("../../../helpers/constants/SourceEnum");
const AbstractTransformation_1 = require("@golemio/core/dist/helpers/transformation/AbstractTransformation");
class GreenCenterMeasurementTransformation extends AbstractTransformation_1.AbstractTransformation {
constructor(transformationDate) {
super();
this.transformationDate = transformationDate;
this.name = "GreenCenterMeasurementTransformation";
this.aggregateCollection = (data) => {
const validData = data.filter((el) => el.visible);
if (!validData.length) {
throw new Error(`Aggregation invalid.`);
}
return validData.reduce((acc, el) => ({
capacity: acc.capacity + el.capacity,
engage: acc.engage + el.engage,
}), {
capacity: 0,
engage: 0,
});
};
this.transformInternal = (data) => {
return {
source: SourceEnum_1.SourceEnum.GREEN_CENTER,
source_id: data.source_id,
parking_id: data.id,
total_spot_number: data.capacity,
available_spot_number: data.capacity - data.engage,
occupied_spot_number: data.engage,
date_modified: this.transformationDate.toISOString(),
};
};
}
}
exports.GreenCenterMeasurementTransformation = GreenCenterMeasurementTransformation;
//# sourceMappingURL=GreenCenterMeasurementTransformation.js.map