diff --git a/services/client/common/models/client-observation.js b/services/client/common/models/client-observation.js index b9f9a4c04..39470f4c7 100644 --- a/services/client/common/models/client-observation.js +++ b/services/client/common/models/client-observation.js @@ -1,7 +1,4 @@ module.exports = function(Self) { - - let loopBackContext = require('loopback-context'); - Self.validate('text', isEnabled, {message: 'Se debe rellenar el campo de texto'}); function isEnabled(err) { if (!this.text) err(); @@ -9,15 +6,15 @@ module.exports = function(Self) { Self.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){ + 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){ if (user){ ctx.instance.employeeFk = user.id; next(); } - }); + }); }); };