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

24 lines
797 B
JavaScript

module.exports = function(ClientObservation) {
let loopBackContext = require('loopback-context');
ClientObservation.validate('text', isEnabled, {message: 'Se debe rellenar el campo de texto'});
function isEnabled(err) {
if (!this.text) err();
}
ClientObservation.observe('before save', function(ctx, next) {
ctx.instance.created = Date();
let currentUser = loopBackContext.getCurrentContext();
let userId = currentUser.get('currentUser');
let app = require('../../server/server');
let employee = app.models.Employee;
employee.findOne({where: {userFk: userId}}, function (err, user){
if (user){
ctx.instance.employeeFk = user.id;
next();
}
});
});
};