@universis/candidates
Version:
Universis api server plugin for study program candidates, internship selection etc
93 lines (79 loc) • 3.43 kB
JavaScript
;Object.defineProperty(exports, "__esModule", { value: true });exports.beforeRemove = beforeRemove;
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);});};}
/*
async function beforeSaveAsync(event) {
const context = event.model.context;
const target = event.target;
const previous = event.previous;
const inscriptionMode =
target.inscriptionMode || (previous && previous.inscriptionMode);
const inscriptionYear =
target.inscriptionYear || (previous && previous.inscriptionYear);
const inscriptionNumber =
target.inscriptionNumber || (previous && previous.inscriptionNumber);
if (!(inscriptionYear && inscriptionMode && inscriptionNumber)) {
throw Object.assign(
new DataError(
'E_CONSTRAINT_ATTRIBUTES',
'The inscription year, inscription number and inscription mode may not be empty because they are part of a unique constraint.',
null,
'CandidateStudent'
),
{
statusCode: 409,
}
);
}
// try to find if another candidate exists with that attributes tuplet
const candidate = await context
.model('CandidateStudent')
.where('inscriptionYear')
.equal(inscriptionYear.id || inscriptionYear)
.and('inscriptionMode')
.equal(inscriptionMode.id || inscriptionMode)
.and('inscriptionNumber')
.equal(inscriptionNumber.toString())
.and('id')
.notEqual(target.id) // notEqual null for insert state
.select('id')
.silent()
.getItem();
// if it does
if (candidate) {
// set target id to candidate's id
event.target.id = candidate.id;
// set previous state if not set
if (event.previous == null) {
event.previous = event.target;
}
// send for update on the fly
event.state = 2;
}
}
*/
/*
export function beforeSave(event, callback) {
return beforeSaveAsync(event)
.then(() => {
return callback();
})
.catch((err) => {
return callback(err);
});
}
*/function
beforeRemoveAsync(_x) {return _beforeRemoveAsync.apply(this, arguments);}
/**
* @param {DataEventArgs} event
* @param {Function} callback
*/function _beforeRemoveAsync() {_beforeRemoveAsync = _asyncToGenerator(function* (event) {const model = event.model;const getReferenceMappings = _data.DataModel.prototype.getReferenceMappings;model.getReferenceMappings = /*#__PURE__*/_asyncToGenerator(function* () {const res = yield getReferenceMappings.bind(this)(); // remove CandidateStudentUploadActionResult mappings
const mappings = ['CandidateStudentUploadActionResult'];return res.filter(mapping => {return mappings.indexOf(mapping.childModel) < 0;});});});return _beforeRemoveAsync.apply(this, arguments);}function beforeRemove(event, callback) {
return beforeRemoveAsync(event).
then(() => {
return callback();
}).
catch(err => {
return callback(err);
});
}
//# sourceMappingURL=candidate-student-listener.js.map