2017-10-11 13:36:47 +00:00
|
|
|
module.exports = function(Self) {
|
|
|
|
Self.validate('text', isEnabled, {message: 'Se debe rellenar el campo de texto'});
|
2017-01-18 13:48:35 +00:00
|
|
|
function isEnabled(err) {
|
2017-03-10 10:18:16 +00:00
|
|
|
if (!this.text) err();
|
2017-01-18 13:48:35 +00:00
|
|
|
}
|
|
|
|
|
2017-10-11 13:36:47 +00:00
|
|
|
Self.observe('before save', function(ctx, next) {
|
2017-05-12 13:21:37 +00:00
|
|
|
ctx.instance.created = Date();
|
2017-10-24 12:10:09 +00:00
|
|
|
let token = ctx.options.accessToken;
|
|
|
|
let userId = token && token.userId;
|
|
|
|
let app = require('../../server/server');
|
|
|
|
let Employee = app.models.Employee;
|
|
|
|
Employee.findOne({where: {userFk: userId}}, function (err, user){
|
2017-11-16 12:47:18 +00:00
|
|
|
if (user) {
|
2017-06-01 11:52:13 +00:00
|
|
|
ctx.instance.employeeFk = user.id;
|
|
|
|
next();
|
|
|
|
}
|
2017-10-24 12:10:09 +00:00
|
|
|
});
|
2017-01-18 13:48:35 +00:00
|
|
|
});
|
2017-03-10 10:18:16 +00:00
|
|
|
};
|