UNPKG

@golemio/parkings

Version:
41 lines 2.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SaveTskParkingSectionsTask = void 0; const integration_engine_1 = require("@golemio/core/dist/integration-engine"); const TskParkingSectionTransformation_1 = require("../../transformations/TskParkingSectionTransformation"); const UpdateAddressWorker_1 = require("../UpdateAddressWorker"); const SourceEnum_1 = require("../../../helpers/constants/SourceEnum"); const TskParkingFilter_1 = require("../../transformations/TskParkingFilter"); const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors"); class SaveTskParkingSectionsTask extends integration_engine_1.AbstractEmptyTask { constructor(queuePrefix, dataSource, parkingsRepository, parkingTariffRelationsRepository, config) { super(queuePrefix); this.dataSource = dataSource; this.parkingsRepository = parkingsRepository; this.parkingTariffRelationsRepository = parkingTariffRelationsRepository; this.config = config; this.queueName = "saveTskParkingSections"; } async execute() { try { const processingDate = new Date(); const sourceData = await this.dataSource.getAll(); const filteredData = sourceData.filter((parking) => TskParkingFilter_1.TskParkingFilter.isWithinValidityPeriod(parking)); const transformation = new TskParkingSectionTransformation_1.TskParkingSectionTransformation(processingDate); const transformedParkings = transformation.transformArray(filteredData); await this.parkingsRepository.saveActiveParkingsWithoutAddress(transformedParkings, SourceEnum_1.SourceEnum.TSK_V2); const transformedParkingTariffsRelationData = transformation.transformParkingTariffsRelation(filteredData); await this.parkingTariffRelationsRepository.saveTariffsRelations(transformedParkingTariffsRelationData, SourceEnum_1.SourceEnum.TSK_V2, processingDate); const exchange = this.config.getValue("env.RABBIT_EXCHANGE_NAME"); await integration_engine_1.QueueManager.sendMessageToExchange(exchange + "." + UpdateAddressWorker_1.UpdateAddressWorker.workerName.toLowerCase(), "updateMissingParkingsAddresses", {}); } catch (error) { if (error instanceof golemio_errors_1.AbstractGolemioError) { throw error; } throw new golemio_errors_1.GeneralError("Error while saving TSK parking sections", this.constructor.name, error); } } } exports.SaveTskParkingSectionsTask = SaveTskParkingSectionsTask; //# sourceMappingURL=SaveTskParkingSectionsTask.js.map