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

19 lines
575 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: {userFk: userId}}, (err, user) => {
if (err) return next(err);
ctx.instance.workerFk = user.id;
next();
});
});
};