salix/services/client/common/models/client-observation.js

21 lines
670 B
JavaScript

module.exports = function(Self) {
Self.validate('text', isEnabled, {message: 'Se debe rellenar el campo de texto'});
function isEnabled(err) {
if (!this.text) err();
}
Self.observe('before save', function(ctx, next) {
ctx.instance.created = Date();
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}}, (err, user) => {
if (user) {
ctx.instance.employeeFk = user.id;
next();
}
});
});
};