Skip to content

Commit

Permalink
Added features to debug(). context.params keys & display selected val…
Browse files Browse the repository at this point in the history
…ues.
  • Loading branch information
eddyystop committed Nov 23, 2017
1 parent a132577 commit 89befaf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/services/debug.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@

module.exports = function (msg) {
module.exports = function (msg, ...fieldNames) {
return context => {
console.log(`* ${msg || ''}\ntype:${context.type}, method: ${context.method}`);
if (context.data) { console.log('data:', context.data); }
if (context.params && context.params.query) { console.log('query:', context.params.query); }
if (context.result) { console.log('result:', context.result); }

const params = context.params || {};
console.log('params props:', Object.keys(params).sort());

fieldNames.forEach(name => {
console.log(`params.${name}:`, params[name]);
});

if (context.error) { console.log('error', context.error); }
};
};
11 changes: 11 additions & 0 deletions tests/services/debug.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@ describe('services debug', () => {
};
hooksCommon.debug('my message')(hook);
});

it('display params props', () => {
const hook = {
type: 'before',
method: 'create',
data: { a: 'a' },
params: { query: { b: 'b' }, foo: 'bar' },
result: { c: 'c' }
};
hooksCommon.debug('my message', 'query', 'foo')(hook);
});
});

0 comments on commit 89befaf

Please sign in to comment.