salix/modules/ticket/back/models/ticket-request.js

14 lines
478 B
JavaScript
Raw Normal View History

2018-11-13 10:26:36 +00:00
const LoopBackContext = require('loopback-context');
module.exports = function(Self) {
Self.observe('before save', async function(ctx) {
if (ctx.isNewInstance) {
const loopBackContext = LoopBackContext.getCurrentContext();
let filter = {where: {userFk: loopBackContext.active.accessToken.userId}};
let worker = await Self.app.models.Worker.findOne(filter);
ctx.instance.requesterFk = worker.id;
}
});
};