loopback-softdelete-mixin
loopback-softdelete-mixin copied to clipboard
Delete operation hook is not working
Hi. Thanks for writing this mixin.
While I use this mixin, I face a situation to use a 'before delete' hook. So I added and tested, but not working.
By reading this mixin's sourcecode, I found that this mixin is overwriting the original loopback PersistedModel's delete methods to its own function. Due to that, it removes the loopback's default operation hook behavior which looks like unintended side effect.
I tried to add remote hook named 'destroyById' method but it also not working.
How do I add 'before delete' hook at current state? My one idea is, create custom delete method and before or after call the destoryById method add my custom behavor like operation hook. Any idea for this?
I did something like this:
Model.destroyById = (id, next) => {
return softDestroy({ id }, next).then((result) => {
Model.notifyObserversOf('after delete', {
instance: {
id: id
}
});
return result[0];
});
};