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

24 lines
797 B
JavaScript
Raw Normal View History

2017-01-18 13:48:35 +00:00
module.exports = function(ClientObservation) {
2017-06-01 11:52:13 +00:00
let loopBackContext = require('loopback-context');
2017-03-10 10:18:16 +00:00
ClientObservation.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-03-10 10:18:16 +00:00
ClientObservation.observe('before save', function(ctx, next) {
2017-05-12 13:21:37 +00:00
ctx.instance.created = Date();
2017-06-01 11:52:13 +00:00
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();
}
});
2017-01-18 13:48:35 +00:00
});
2017-03-10 10:18:16 +00:00
};