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

19 lines
582 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;
Self.app.models.Worker.findOne({where: {userFk: userId}}, (err, user) => {
if (err) return next(err);
ctx.instance.workerFk = user.id;
next();
});
});
};