UNPKG

@universis/candidates

Version:

Universis api server plugin for study program candidates, internship selection etc

134 lines (121 loc) 5.59 kB
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.CandidateService = void 0;var _common = require("@themost/common"); var _data = require("@themost/data"); var _fs = _interopRequireDefault(require("fs")); var _path = _interopRequireDefault(require("path")); var _pluralize = _interopRequireDefault(require("pluralize")); require("./DataFilterExtensions"); var _scopeAccess = _interopRequireDefault(require("./config/scope.access.json")); var _StudyProgramReplacer = require("./StudyProgramReplacer"); var _express = _interopRequireDefault(require("express"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}const { studyProgramEnrollmentEventRouter } = require('./studyProgramEnrollmentEventRouter'); class CandidateService extends _common.ApplicationService { /** * @param {IApplication|*} app */ constructor(app) { super(app); // extend StudyProgram new _StudyProgramReplacer.StudyProgramReplacer(app).apply(); this.install(); // extend application service router if (app.container) { app.container.subscribe(container => { if (app && app.serviceRouter) { // subscribe to serviceRouter app.serviceRouter.subscribe(serviceRouter => { // add extra scope access elements const scopeAccess = app.getConfiguration().getStrategy(function ScopeAccessConfiguration() {}); if (scopeAccess != null) { scopeAccess.elements.push.apply(scopeAccess.elements, _scopeAccess.default); } const addRouter = _express.default.Router(); addRouter.use('/StudyProgramEnrollmentEvents', studyProgramEnrollmentEventRouter(app.getConfiguration())); // insert router at the beginning of serviceRouter.stack serviceRouter.stack.unshift.apply(serviceRouter.stack, addRouter.stack); }); } }); } // register templates // get MailTemplateService by name const mailTemplateService = this.getApplication().getService(function MailTemplateService() {}); if (mailTemplateService != null) { mailTemplateService.extraTemplates.push({ name: 'new-candidate-user', path: _path.default.resolve(__dirname, './templates/new-candidate-user/html.ejs') }); mailTemplateService.extraTemplates.push({ name: 'new-message', path: _path.default.resolve(__dirname, './templates/new-message/html.ejs') }); mailTemplateService.extraTemplates.push({ name: 'send-sms', path: _path.default.resolve(__dirname, './templates/send-sms/html.ejs') }); // mailTemplateService.extraTemplates.push({ // name: 'direct-message', // path: path.resolve(__dirname, './templates/direct-message/html.ejs') // }); mailTemplateService.extraTemplates.push({ name: 'register-status-change', path: _path.default.resolve(__dirname, './templates/register-status-change/html.ejs') }); mailTemplateService.extraTemplates.push({ name: 'direct-email-to-candidate', path: _path.default.resolve(__dirname, './templates/direct-email-to-candidate/html.ejs') }); } } install() { // place your code here /** * get data configuration * @type {DataConfigurationStrategy} */ const configuration = this.getApplication().getConfiguration().getStrategy(_data.DataConfigurationStrategy); // noinspection JSValidateTypes /** * get model builder * @type {ODataModelBuilder} */ const builder = this.getApplication().getStrategy(_data.ODataModelBuilder); // load models const files = _fs.default.readdirSync(_path.default.resolve(__dirname, 'config/models')).filter(file => _path.default.extname(file) === '.json'); files.forEach(file => { // load model definition const model = require(_path.default.resolve(__dirname, 'config/models', file)); // try to get model from application (if model definition does not exists in parent configuration) if (configuration.model(model.name) == null) { // set model definition if (Array.isArray(model.eventListeners)) { model.eventListeners.forEach(eventListener => { if (eventListener.type.indexOf('.') === 0) { eventListener.type = _path.default.resolve(__dirname, eventListener.type); } }); } if (model.classPath && model.classPath.indexOf('.') === 0) { model.classPath = _path.default.resolve(__dirname, model.classPath); } configuration.setModelDefinition(model); } }); files.forEach(file => { // load model definition const model = require(_path.default.resolve(__dirname, 'config/models', file)); if (builder) { let entitySet = _pluralize.default.plural(model.name); // add entity set (for odata endpoints) builder.addEntitySet(model.name, entitySet); // check if model is hidden if (model.hidden) { // and ignore it builder.ignore(model.name); } // refresh model entity set (function refreshEntitySet(entityType, entitySet) { builder.removeEntitySet(entitySet); builder.addEntitySet(entityType, entitySet); })(model.name, entitySet); } }); } // noinspection JSUnusedGlobalSymbols uninstall() { // place your code here }}exports.CandidateService = CandidateService; //# sourceMappingURL=CandidateService.js.map