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