1-
21/*
32 How the softDelete2 hook is to be positioned relative to other possible hooks:
43
5958
6059const errors = require ( '@feathersjs/errors' ) ;
6160const SKIP = require ( '@feathersjs/feathers' ) . SKIP ;
62- const { callingParams } = require ( './calling-params' ) ;
61+ const {
62+ callingParams
63+ } = require ( './calling-params' ) ;
6364
6465const defaultDeletedAt = 'deletedAt' ;
6566const 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+ }
0 commit comments