@universis/candidates
Version:
Universis api server plugin for study program candidates, internship selection etc
59 lines (17 loc) • 2.74 kB
JavaScript
;Object.defineProperty(exports, "__esModule", { value: true });exports.beforeSave = beforeSave;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
beforeSaveAsync(_x) {return _beforeSaveAsync.apply(this, arguments);}
/**
* @param {DataEventArgs} event
* @param {Function} callback
*/function _beforeSaveAsync() {_beforeSaveAsync = _asyncToGenerator(function* (event) {const context = event.model.context;let actionStatus;if (Object.prototype.hasOwnProperty.call(event.target, 'actionStatus') === false) {return;} // find current action status
actionStatus = yield context.model('ActionStatusTypes').find(event.target.actionStatus).select('alternateName').value();if (event.state === 2) {// get previous status
let previousStatus = 'UnknownActionStatus';if (event.previous) {previousStatus = event.previous.actionStatus.alternateName;} else {throw new _data.DataError('E_STATE', 'The previous state of an object cannot be determined', null, 'StudyProgramRegisterAction');}if (previousStatus === 'PotentialActionStatus' && actionStatus === 'PotentialActionStatus') {//save also candidatePerson info
if (event.target.candidate.person) {const data = { id: event.target.candidate.id, person: event.target.candidate.person };yield context.model('CandidateStudent').save(data);}}if (previousStatus === 'PotentialActionStatus' && actionStatus === 'ActiveActionStatus') {event.target.endTime = new Date();}if (previousStatus === 'ActiveActionStatus' && actionStatus === 'CompletedActionStatus') {event.target.accepted = 1;}if (previousStatus === 'ActiveActionStatus' && actionStatus === 'CancelledActionStatus') {event.target.rejected = 1;}} else if (event.state === 1) {if (actionStatus === 'ActiveActionStatus') {event.target.endTime = new Date();}}});return _beforeSaveAsync.apply(this, arguments);}function beforeSave(event, callback) {return beforeSaveAsync(event).then(() => {return callback();
}).catch(err => {
return callback(err);
});
}
//# sourceMappingURL=set-submission-time-listener.js.map