@golemio/pid
Version:
Golemio PID Module
111 lines • 6.25 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InfotextFacade = void 0;
const JISInfotextRepository_1 = require("../../data-access/JISInfotextRepository");
const JISInfotextStopSuppressionFilter_1 = require("../../helpers/JISInfotextStopSuppressionFilter");
const OgPidToken_1 = require("../../ioc/OgPidToken");
const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
const JISInfotextDepartureTransformation_1 = require("../transformations/JISInfotextDepartureTransformation");
const JISInfotextOverviewTransformation_1 = require("../transformations/JISInfotextOverviewTransformation");
const JISInfotextTransferTransformation_1 = require("../transformations/JISInfotextTransferTransformation");
let InfotextFacade = exports.InfotextFacade = class InfotextFacade {
constructor(infotextRepository, infotextDepartureTransformation, infotextTransferTransformation, infotextOverviewTransformation, infotextStopFilter) {
this.infotextRepository = infotextRepository;
this.infotextDepartureTransformation = infotextDepartureTransformation;
this.infotextTransferTransformation = infotextTransferTransformation;
this.infotextOverviewTransformation = infotextOverviewTransformation;
this.infotextStopFilter = infotextStopFilter;
}
async getInfotextsForDepartureBoards(stopIds, currentMoment, options) {
try {
const infotexts = await this.infotextRepository.findAllForDepartureBoard(stopIds, (options.timeFrom ?? currentMoment).toDate());
if (infotexts.length === 0) {
return [];
}
const filteredInfotexts = this.infotextStopFilter.filterBySeverityLevel(infotexts);
if (filteredInfotexts.length === 0) {
return [];
}
const infotextsToInclude = [];
for (const infotext of filteredInfotexts) {
const infotextDto = this.infotextDepartureTransformation.transformElement({
data: infotext,
timeZone: options.timezone,
});
infotextsToInclude.push(infotextDto);
}
return infotextsToInclude;
}
catch (error) {
if (error instanceof golemio_errors_1.AbstractGolemioError) {
throw error;
}
throw new golemio_errors_1.GeneralError("Failed to retrieve infotexts for departure boards", this.constructor.name, error, 500);
}
}
async getInfotextsForTransferBoards(stopIds, currentMoment, timeFrom) {
try {
const infotexts = await this.infotextRepository.findAllForDepartureBoard(stopIds, timeFrom ? timeFrom.toDate() : currentMoment.toDate());
if (infotexts.length === 0) {
return [];
}
const filteredInfotexts = this.infotextStopFilter.filterBySeverityLevel(infotexts);
if (filteredInfotexts.length === 0) {
return [];
}
return this.infotextTransferTransformation.transformArray(filteredInfotexts);
}
catch (error) {
if (error instanceof golemio_errors_1.AbstractGolemioError) {
throw error;
}
throw new golemio_errors_1.GeneralError("Failed to retrieve infotexts for transfer boards", this.constructor.name, error, 500);
}
}
async getInfotextsForOverview() {
try {
const infotexts = await this.infotextRepository.findAllForOverview();
if (infotexts.length === 0) {
return [];
}
const filteredInfotexts = this.infotextStopFilter.filterBySeverityLevel(infotexts);
if (filteredInfotexts.length === 0) {
return [];
}
return this.infotextOverviewTransformation.transformArray(filteredInfotexts);
}
catch (error) {
if (error instanceof golemio_errors_1.AbstractGolemioError) {
throw error;
}
throw new golemio_errors_1.GeneralError("Failed to retrieve infotexts for overview", this.constructor.name, error, 500);
}
}
};
exports.InfotextFacade = InfotextFacade = __decorate([
(0, tsyringe_1.injectable)(),
__param(0, (0, tsyringe_1.inject)(OgPidToken_1.OgPidToken.JISInfotextRepository)),
__param(1, (0, tsyringe_1.inject)(OgPidToken_1.OgPidToken.JISInfotextDepartureTransformation)),
__param(2, (0, tsyringe_1.inject)(OgPidToken_1.OgPidToken.JISInfotextTransferTransformation)),
__param(3, (0, tsyringe_1.inject)(OgPidToken_1.OgPidToken.JISInfotextOverviewTransformation)),
__param(4, (0, tsyringe_1.inject)(OgPidToken_1.OgPidToken.JISInfotextStopSuppressionFilter)),
__metadata("design:paramtypes", [JISInfotextRepository_1.JISInfotextRepository,
JISInfotextDepartureTransformation_1.JISInfotextDepartureTransformation,
JISInfotextTransferTransformation_1.JISInfotextTransferTransformation,
JISInfotextOverviewTransformation_1.JISInfotextOverviewTransformation,
JISInfotextStopSuppressionFilter_1.JISInfotextStopSuppressionFilter])
], InfotextFacade);
//# sourceMappingURL=InfotextFacade.js.map