Skip to content

Commit d7f3f01

Browse files
committed
🐞 tmp fix for issue with soft-delete-2
1 parent f7a61d3 commit d7f3f01

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

lib/services/soft-delete-2.js

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
How the softDelete2 hook is to be positioned relative to other possible hooks:
43
@@ -59,7 +58,9 @@
5958

6059
const errors = require('@feathersjs/errors');
6160
const SKIP = require('@feathersjs/feathers').SKIP;
62-
const { callingParams } = require('./calling-params');
61+
const {
62+
callingParams
63+
} = require('./calling-params');
6364

6465
const defaultDeletedAt = 'deletedAt';
6566
const deletedMessage = 'Record not found, is logically deleted.';
@@ -91,7 +92,9 @@ module.exports = function (options = {}) {
9192

9293
const result = context.result ? context.result.data || context.result : null;
9394
if (skipProbeOnGet && result && result[deletedAt] >= 0) {
94-
throw new errors.NotFound(deletedMessage, { id: context.id });
95+
throw new errors.NotFound(deletedMessage, {
96+
id: context.id
97+
});
9598
}
9699

97100
return context;
@@ -115,9 +118,9 @@ module.exports = function (options = {}) {
115118
case 'create':
116119
const data = context.data;
117120

118-
context.data = Array.isArray(data)
119-
? data.map(rec => addField(rec, deletedAt, -1, keepOnCreate))
120-
: addField(data, deletedAt, -1, keepOnCreate);
121+
context.data = Array.isArray(data) ?
122+
data.map(rec => addField(rec, deletedAt, -1, keepOnCreate)) :
123+
addField(data, deletedAt, -1, keepOnCreate);
121124

122125
return context;
123126
case 'get':
@@ -149,36 +152,48 @@ module.exports = function (options = {}) {
149152
};
150153
};
151154

152-
async function getActiveRecord (options, context) {
155+
async function getActiveRecord(options, context) {
153156
const record = await (options.probeCall || defaultProbeCall)(context, options);
154157

155158
if (record[options.deletedAt || defaultDeletedAt] > -1) {
156-
throw new errors.NotFound(deletedMessage, { id: context.id });
159+
throw new errors.NotFound(deletedMessage, {
160+
id: context.id
161+
});
157162
}
158163

159164
return record;
160165
}
161166

162-
async function defaultProbeCall (context, options) {
167+
async function defaultProbeCall(context, options) {
163168
const params = callingParams({
164-
newProps: { provider: undefined }, hooksToDisable: ['softDelete2']
169+
newProps: {
170+
provider: undefined
171+
},
172+
hooksToDisable: ['softDelete2']
165173
})(context);
166174

167175
return context.service.get(context.id, params);
168176
}
169177

170-
async function defaultPatchCall (context, options) {
178+
async function defaultPatchCall(context, options) {
171179
const deletedAt = options.deletedAt || defaultDeletedAt;
172180

173181
const params = callingParams({
174-
query: Object.assign({}, context.params.query, { [deletedAt]: -1 }),
175-
newProps: { provider: undefined },
182+
query: Object.assign({}, context.params.query, {
183+
/*[deletedAt]: -1 */ }),
184+
newProps: {
185+
provider: undefined
186+
},
176187
hooksToDisable: ['softDelete2']
177188
})(context);
178189

179-
return context.service.patch(context.id, { [deletedAt]: Date.now() }, params);
190+
return context.service.patch(context.id, {
191+
[deletedAt]: Date.now()
192+
}, params);
180193
}
181194

182-
function addField (obj = {}, name, value, keep) {
183-
return (name in obj) && keep ? obj : Object.assign({}, obj, { [name]: value });
184-
}
195+
function addField(obj = {}, name, value, keep) {
196+
return (name in obj) && keep ? obj : Object.assign({}, obj, {
197+
[name]: value
198+
});
199+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "feathers-hooks-common",
3-
"version": "4.20.7",
3+
"version": "4.20.8",
44
"description": "Useful hooks for use with Feathersjs services.",
55
"main": "lib/",
66
"types": "types/",
@@ -90,4 +90,4 @@
9090
"engines": {
9191
"node": ">= 6"
9292
}
93-
}
93+
}

0 commit comments

Comments
 (0)