module.exports = function(Self) { Self.validate('text', function(err) { if (!this.text) err(); }, {message: 'Description cannot be blank'}); Self.validate('observationTypeFk', function(err) { if (!this.observationTypeFk) err(); }, {message: 'type cannot be blank'}); 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: {id: userId}}, (err, user) => { if (err) return next(err); ctx.instance.workerFk = user.id; next(); }); }); };