salix/modules/client/back/models/greuge.js

24 lines
613 B
JavaScript

const LoopBackContext = require('loopback-context');
module.exports = function(Self) {
require('../methods/greuge/sumAmount')(Self);
Self.observe('before save', function(ctx, next) {
const loopBackContext = LoopBackContext.getCurrentContext();
let userFk = loopBackContext.active.accessToken.userId;
if (ctx.instance)
ctx.instance.userFk = userFk;
else
ctx.data.userFk = userFk;
next();
});
Self.validatesLengthOf('description', {
max: 45,
message: 'Description should have maximum of 45 characters'
});
};