2023-11-13 08:53:35 +00:00
|
|
|
const LoopBackContext = require('loopback-context');
|
|
|
|
async function handleObserve(ctx) {
|
2024-03-14 07:36:19 +00:00
|
|
|
const httpCtx = LoopBackContext.getCurrentContext();
|
|
|
|
ctx.options.userId = httpCtx?.active?.accessToken?.userId;
|
2023-11-13 08:53:35 +00:00
|
|
|
}
|
|
|
|
module.exports = function(Self) {
|
|
|
|
let Mixin = {
|
|
|
|
'before save': handleObserve,
|
|
|
|
'before delete': handleObserve,
|
|
|
|
};
|
|
|
|
for (const [listener, handler] of Object.entries(Mixin))
|
|
|
|
Self.observe(listener, handler);
|
|
|
|
};
|