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