UNPKG

@universis/candidates

Version:

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

88 lines (17 loc) 3.67 kB
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.afterSave = afterSave;var _data = require("@themost/data");function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try {var info = gen[key](arg);var value = info.value;} catch (error) {reject(error);return;}if (info.done) {resolve(value);} else {Promise.resolve(value).then(_next, _throw);}}function _asyncToGenerator(fn) {return function () {var self = this,args = arguments;return new Promise(function (resolve, reject) {var gen = fn.apply(self, args);function _next(value) {asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);}function _throw(err) {asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);}_next(undefined);});};} /** * @param {DataEventArgs} event */function afterSaveAsync(_x) {return _afterSaveAsync.apply(this, arguments);} /** * @param {DataEventArgs} event * @param {Function} callback */function _afterSaveAsync() {_afterSaveAsync = _asyncToGenerator(function* (event) {const context = event.model.context; // get original data const actionStatus = yield context.model('StudyProgramRegisterAction').where('id').equal(event.target.id).select('actionStatus/alternateName').value();let shouldUpdateChildren = false;const ValidActionStatusTypes = ['CompletedActionStatus', 'PotentialActionStatus', 'ActiveActionStatus', 'FailedActionStatus', 'CancelledActionStatus'];if (event.state === _data.DataObjectState.Insert) {if (ValidActionStatusTypes.includes(actionStatus)) {shouldUpdateChildren = true;}} // get previous status let previousStatus = 'UnknownActionStatus';if (event.state === _data.DataObjectState.Update) {if (event.previous) {previousStatus = event.previous.actionStatus.alternateName;}if (ValidActionStatusTypes.includes(actionStatus) && actionStatus !== previousStatus) {shouldUpdateChildren = true;}}if (shouldUpdateChildren) {const children = yield context.model('CourseClassRegisterAction').where('initiator').equal(event.target.id).select('id', 'actionStatus').silent().getItems(); // when if (children.length) {children.forEach(child => {if (actionStatus === 'CompletedActionStatus') {if (child.actionStatus.alternateName === 'ActiveActionStatus') {child.actionStatus = { alternateName: 'CompletedActionStatus' };}} // when an application is becoming children should also become active if (previousStatus === 'PotentialActionStatus' && actionStatus === 'ActiveActionStatus') {child.actionStatus = { alternateName: 'ActiveActionStatus' };} // when an application is reverted to potential children should be updated alos if (previousStatus === 'ActiveActionStatus' && actionStatus === 'PotentialActionStatus') {child.actionStatus = { alternateName: 'PotentialActionStatus' };} // when an application is being rejected children should also be rejected if (actionStatus === 'CancelledActionStatus' && previousStatus !== 'CancelledActionStatus') {child.actionStatus = { alternateName: 'CancelledActionStatus' };} // when an application is being activated children should also be activated if (actionStatus === 'ActiveActionStatus' && previousStatus !== 'ActiveActionStatus') {child.actionStatus = { alternateName: 'ActiveActionStatus' };}});}yield context.model('CourseClassRegisterAction').silent().save(children);}});return _afterSaveAsync.apply(this, arguments);}function afterSave(event, callback) {return afterSaveAsync(event).then(() => {return callback();}).catch(err => {return callback(err);});} //# sourceMappingURL=set-course-registration-status-listener.js.map