From a102c3f3a952da468734039c1e133e4470270842 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 13 Nov 2023 09:53:35 +0100 Subject: [PATCH] refs #5666 perf: loggable to mixin --- loopback/common/mixins/loggable.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 loopback/common/mixins/loggable.js diff --git a/loopback/common/mixins/loggable.js b/loopback/common/mixins/loggable.js new file mode 100644 index 000000000..760fdf60a --- /dev/null +++ b/loopback/common/mixins/loggable.js @@ -0,0 +1,12 @@ +const LoopBackContext = require('loopback-context'); +async function handleObserve(ctx) { + ctx.options.httpCtx = LoopBackContext.getCurrentContext(); +} +module.exports = function(Self) { + let Mixin = { + 'before save': handleObserve, + 'before delete': handleObserve, + }; + for (const [listener, handler] of Object.entries(Mixin)) + Self.observe(listener, handler); +};