@universis/candidates
Version:
Universis api server plugin for study program candidates, internship selection etc
62 lines (33 loc) • 2.75 kB
JavaScript
;Object.defineProperty(exports, "__esModule", { value: true });exports.afterSave = afterSave;exports.afterRemove = afterRemove;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
*/function _afterSaveAsync() {_afterSaveAsync = _asyncToGenerator(function* (event) {const context = event.model.context;const item = yield context.model('Internship').where('id').equal(event.target.id).silent().expand('status').getItem(); // convert to available internship
const AvailableInternships = context.model('AvailableInternship');const copyItem = {}; // copy data
AvailableInternships.attributes.forEach(attribute => {copyItem[attribute.name] = item[attribute.name];}); // validate existence
const exists = yield AvailableInternships.where('id').equal(event.target.id).silent().count();if (exists) {yield AvailableInternships.silent().save(copyItem);} else {yield AvailableInternships.silent().insert(copyItem);}});return _afterSaveAsync.apply(this, arguments);}function afterRemoveAsync(_x2) {return _afterRemoveAsync.apply(this, arguments);}
/**
* @param {DataEventArgs} event
* @param {Function} callback
*/function _afterRemoveAsync() {_afterRemoveAsync = _asyncToGenerator(function* (event) {const context = event.model.context;const AvailableInternships = context.model('AvailableInternship');const exists = AvailableInternships.where('id').equal(event.target.id).silent().count();if (exists) {yield AvailableInternships.silent().remove({ id: event.target.id });}});return _afterRemoveAsync.apply(this, arguments);}
function afterSave(event, callback) {
return afterSaveAsync(event).then(() => {
return callback();
}).catch(err => {
return callback(err);
});
}
/**
* @param {DataEventArgs} event
* @param {Function} callback
*/
function afterRemove(event, callback) {
return afterRemoveAsync(event).then(() => {
return callback();
}).catch(err => {
return callback(err);
});
}
//# sourceMappingURL=set-available-internship-listener.js.map