Skip to content

Commit 1968431

Browse files
modify stashBefore hook, move $disableStashBefore from query to params (#555)
* feat move $disableStashBefore from query to params * Rename $disableStashBefore to disableStashBefore * Add vscode launch script for debugging Mocha tests (#554) * Add vscode script for debugging tests * Remove default comment from launch.json * stash-before: Don’t modify existing params
1 parent 3a8d73e commit 1968431

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

lib/services/calling-params.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ function callingParams ({ query, propNames = [], newProps = {}, hooksToDisable =
5959
newParams.$ignoreDeletedAt = true;
6060
break;
6161
case 'stashBefore':
62-
newParams.query = newParams.query || {};
63-
newParams.query.$disableStashBefore = true;
62+
newParams.disableStashBefore = true;
6463
break;
6564
}
6665
});

lib/services/stash-before.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ module.exports = function (prop) {
88
return context => {
99
checkContext(context, 'before', ['get', 'update', 'patch', 'remove'], 'stashBefore');
1010

11-
if (context.params.query && context.params.query.$disableStashBefore) {
12-
delete context.params.query.$disableStashBefore;
11+
if (context.params.disableStashBefore) {
1312
return context;
1413
}
1514

@@ -23,13 +22,12 @@ module.exports = function (prop) {
2322
user: context.params.user
2423
};
2524

26-
params.query = params.query || {};
27-
params.query.$disableStashBefore = true;
28-
29-
return context.service.get(context.id, params)
25+
return context.service.get(context.id, {
26+
...params,
27+
query: params.query || {},
28+
disableStashBefore: true
29+
})
3030
.then(data => {
31-
delete params.query.$disableStashBefore;
32-
3331
context.params[beforeField] = JSON.parse(JSON.stringify(data));
3432
return context;
3533
})

tests/services/calling-params-1.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ describe('service calling-params-1.test.js', () => {
117117
provider: 'socketio',
118118
user: { name: 'Matt' },
119119
_populate: 'skip',
120-
query: { $disableSoftDelete: true, $disableStashBefore: true }
120+
disableStashBefore: true,
121+
query: { $disableSoftDelete: true }
121122
});
122123
});
123124

@@ -143,7 +144,8 @@ describe('service calling-params-1.test.js', () => {
143144
hooksToDisable: ['populate', 'fastJoin', 'softDelete', 'stashBefore']
144145
})(context1);
145146
assert.deepEqual(res, {
146-
query: { id: 1, aa: 'a1', $disableSoftDelete: true, $disableStashBefore: true },
147+
disableStashBefore: true,
148+
query: { id: 1, aa: 'a1', $disableSoftDelete: true },
147149
foo: 'bar',
148150
baz: 'faz',
149151
_populate: 'skip',

tests/services/stash-before.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function users () {
3636
before: {
3737
all: [
3838
context => {
39-
if ((context.params.query || {}).$disableStashBefore === true) {
39+
if (context.params.disableStashBefore === true) {
4040
innerCallParams = context.params;
4141
}
4242
},

0 commit comments

Comments
 (0)