UNPKG

@golemio/parkings

Version:
37 lines 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UpdateStaticTariffsTask = void 0; const SourceEnum_1 = require("../../../helpers/constants/SourceEnum"); const integration_engine_1 = require("@golemio/core/dist/integration-engine"); const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors"); class UpdateStaticTariffsTask extends integration_engine_1.AbstractEmptyTask { constructor(queuePrefix, dataSource, transformer, parkingTariffsRepository, parkingTariffRelationsRepository, matcher) { super(queuePrefix); this.queueName = "updateStaticTariffs"; this.queueTtl = 60 * 60 * 1000; // 1 hour this.dataSource = dataSource; this.transformer = transformer; this.parkingTariffsRepository = parkingTariffsRepository; this.parkingTariffRelationsRepository = parkingTariffRelationsRepository; this.matcher = matcher; } async execute() { try { const data = await this.dataSource.getAll(); const transformedData = await this.transformer.transform(data.tariffs); await this.parkingTariffsRepository.save(transformedData); const matches = await this.matcher.matchTariffRelations(data.relations); await this.parkingTariffRelationsRepository.saveTariffsRelations(matches, SourceEnum_1.SourceEnum.Manual); } catch (err) { if (err instanceof golemio_errors_1.AbstractGolemioError) { throw err; } else { throw new golemio_errors_1.GeneralError(`Error while refreshing static parking tariffs: ${err.message}`, this.constructor.name, err); } } } } exports.UpdateStaticTariffsTask = UpdateStaticTariffsTask; //# sourceMappingURL=UpdateStaticTariffsTask.js.map