14 lines
453 B
JavaScript
14 lines
453 B
JavaScript
const LoopBackContext = require('loopback-context');
|
|
async function handleObserve(ctx) {
|
|
const httpCtx = LoopBackContext.getCurrentContext();
|
|
ctx.options.userId = httpCtx?.active?.accessToken?.userId;
|
|
}
|
|
module.exports = function(Self) {
|
|
let Mixin = {
|
|
'before save': handleObserve,
|
|
'before delete': handleObserve,
|
|
};
|
|
for (const [listener, handler] of Object.entries(Mixin))
|
|
Self.observe(listener, handler);
|
|
};
|