1
-
2
1
/*
3
2
How the softDelete2 hook is to be positioned relative to other possible hooks:
4
3
59
58
60
59
const errors = require ( '@feathersjs/errors' ) ;
61
60
const SKIP = require ( '@feathersjs/feathers' ) . SKIP ;
62
- const { callingParams } = require ( './calling-params' ) ;
61
+ const {
62
+ callingParams
63
+ } = require ( './calling-params' ) ;
63
64
64
65
const defaultDeletedAt = 'deletedAt' ;
65
66
const deletedMessage = 'Record not found, is logically deleted.' ;
@@ -91,7 +92,9 @@ module.exports = function (options = {}) {
91
92
92
93
const result = context . result ? context . result . data || context . result : null ;
93
94
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
+ } ) ;
95
98
}
96
99
97
100
return context ;
@@ -115,9 +118,9 @@ module.exports = function (options = {}) {
115
118
case 'create' :
116
119
const data = context . data ;
117
120
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 ) ;
121
124
122
125
return context ;
123
126
case 'get' :
@@ -149,36 +152,48 @@ module.exports = function (options = {}) {
149
152
} ;
150
153
} ;
151
154
152
- async function getActiveRecord ( options , context ) {
155
+ async function getActiveRecord ( options , context ) {
153
156
const record = await ( options . probeCall || defaultProbeCall ) ( context , options ) ;
154
157
155
158
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
+ } ) ;
157
162
}
158
163
159
164
return record ;
160
165
}
161
166
162
- async function defaultProbeCall ( context , options ) {
167
+ async function defaultProbeCall ( context , options ) {
163
168
const params = callingParams ( {
164
- newProps : { provider : undefined } , hooksToDisable : [ 'softDelete2' ]
169
+ newProps : {
170
+ provider : undefined
171
+ } ,
172
+ hooksToDisable : [ 'softDelete2' ]
165
173
} ) ( context ) ;
166
174
167
175
return context . service . get ( context . id , params ) ;
168
176
}
169
177
170
- async function defaultPatchCall ( context , options ) {
178
+ async function defaultPatchCall ( context , options ) {
171
179
const deletedAt = options . deletedAt || defaultDeletedAt ;
172
180
173
181
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
+ } ,
176
187
hooksToDisable : [ 'softDelete2' ]
177
188
} ) ( context ) ;
178
189
179
- return context . service . patch ( context . id , { [ deletedAt ] : Date . now ( ) } , params ) ;
190
+ return context . service . patch ( context . id , {
191
+ [ deletedAt ] : Date . now ( )
192
+ } , params ) ;
180
193
}
181
194
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
+ }
0 commit comments