2017-10-11 13:36:47 +00:00
|
|
|
module.exports = function(Self) {
|
2018-08-02 07:49:00 +00:00
|
|
|
Self.validate('text', isEnabled, {message: 'Description cannot be blank'});
|
2017-01-18 13:48:35 +00:00
|
|
|
function isEnabled(err) {
|
2017-03-10 10:18:16 +00:00
|
|
|
if (!this.text) err();
|
2017-01-18 13:48:35 +00:00
|
|
|
}
|
|
|
|
|
2017-10-11 13:36:47 +00:00
|
|
|
Self.observe('before save', function(ctx, next) {
|
2017-05-12 13:21:37 +00:00
|
|
|
ctx.instance.created = Date();
|
2017-10-24 12:10:09 +00:00
|
|
|
let token = ctx.options.accessToken;
|
|
|
|
let userId = token && token.userId;
|
2018-01-29 11:37:54 +00:00
|
|
|
|
|
|
|
Self.app.models.Worker.findOne({where: {userFk: userId}}, (err, user) => {
|
|
|
|
if (err) return next(err);
|
|
|
|
ctx.instance.workerFk = user.id;
|
|
|
|
next();
|
2017-10-24 12:10:09 +00:00
|
|
|
});
|
2017-01-18 13:48:35 +00:00
|
|
|
});
|
2017-03-10 10:18:16 +00:00
|
|
|
};
|