Skip to content

Get diff in after hook #2566

Answered by ericuldall
ericuldall asked this question in Q&A
Discussion options

You must be logged in to vote

I just ended up writing a custom before hook to handle it. Using https://npmjs.com/package/deep-diff:

prepareDiff: context => {
        if (context.id) {
            return context.service.get(context.id).then(stash => {
                context.diff = diff(JSON.parse(JSON.stringify(stash)), JSON.parse(JSON.stringify(context.data)));
                return context;
            }).catch(e => {
                console.log(e);
                return context;
            });
        }
        return context;
    }

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by daffl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant
Converted from issue

This discussion was converted from issue #2565 on February 23, 2022 17:13.