salix/modules/client/back/models/client-observation.js

19 lines
571 B
JavaScript

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();
});
});
};