UNPKG

@universis/evaluations

Version:

Universis evaluations library

83 lines (77 loc) 2.91 kB
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.EvaluationService = void 0;var _common = require("@themost/common"); var _scopeAccess = _interopRequireDefault(require("./config/scope.access.json")); var _evaluationRouter = require("./evaluationRouter"); var _mailer = require("@themost/mailer");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} function insertRouterBefore(parent, before, insert) { const beforeIndex = parent.stack.findIndex((item) => { return item === before; }); if (beforeIndex < 0) { throw new Error('Target router cannot be found in parent stack.'); } const findIndex = parent.stack.findIndex((item) => { return item === insert; }); if (findIndex < 0) { throw new Error('Router to be inserted cannot be found in parent stack.'); } // remove last router parent.stack.splice(findIndex, 1); // move up parent.stack.splice(beforeIndex, 0, insert); } class EvaluationService extends _common.ApplicationService { constructor(app) { super(app); // extend universis api scope access configuration if (app && app.container) { app.container.subscribe((container) => { if (container) { // add extra scope access elements const scopeAccess = app.getConfiguration().getStrategy(function ScopeAccessConfiguration() {}); if (scopeAccess != null) { scopeAccess.elements.push.apply(scopeAccess.elements, _scopeAccess.default); } // get container router const router = container._router; // find after position const before = router.stack.find((item) => { return item.name === 'dataContextMiddleware'; }); // use eudoxus router container.use('/api/EvaluationEvents/Current', (0, _evaluationRouter.evaluationRouter)(app)); if (before == null) { // do nothing return; } // get last router const insert = router.stack[router.stack.length - 1]; // insert (re-index) router insertRouterBefore(router, before, insert); } }); } process.on('exit', () => { this.closeMailTransporter(); }); } getMailTransporter() { if (this.transporter) { return this.transporter; } const app = this.getApplication(); const context = app.createContext(); this.transporter = (0, _mailer.getMailer)(context).getTransporter(); return this.transporter; } closeMailTransporter() { try { if (this.transporter && typeof this.transporter.close === "function") { this.transporter.close(); this.transporter = null; } } catch (e) { _common.TraceUtils.error(e); } }}exports.EvaluationService = EvaluationService; //# sourceMappingURL=EvaluationService.js.map