File tree Expand file tree Collapse file tree 2 files changed +42
-12
lines changed Expand file tree Collapse file tree 2 files changed +42
-12
lines changed Original file line number Diff line number Diff line change @@ -1063,17 +1063,31 @@ DataForm.prototype.entityPut = function () {
1063
1063
} ;
1064
1064
DataForm . prototype . entityDelete = function ( ) {
1065
1065
return _ . bind ( function ( req , res , next ) {
1066
- this . processEntity ( req , res , function ( ) {
1067
- if ( ! req . resource ) {
1068
- next ( ) ;
1069
- return ;
1070
- }
1071
- req . doc . remove ( function ( err ) {
1066
+ function internalRemove ( doc ) {
1067
+ doc . remove ( function ( err ) {
1072
1068
if ( err ) {
1073
1069
return res . send ( { success : false } ) ;
1074
1070
}
1075
1071
return res . send ( { success : true } ) ;
1076
1072
} ) ;
1073
+ }
1074
+ this . processEntity ( req , res , function ( ) {
1075
+ if ( ! req . resource ) {
1076
+ next ( ) ;
1077
+ return ;
1078
+ }
1079
+ var doc = req . doc ;
1080
+ if ( typeof req . resource . options . onRemove === 'function' ) {
1081
+ req . resource . options . onRemove ( doc , req , function ( err ) {
1082
+ if ( err ) {
1083
+ throw err ;
1084
+ }
1085
+ internalRemove ( doc ) ;
1086
+ } ) ;
1087
+ }
1088
+ else {
1089
+ internalRemove ( doc ) ;
1090
+ }
1077
1091
} ) ;
1078
1092
} , this ) ;
1079
1093
} ;
Original file line number Diff line number Diff line change @@ -1180,18 +1180,34 @@ DataForm.prototype.entityPut = function () {
1180
1180
DataForm . prototype . entityDelete = function ( ) {
1181
1181
return _ . bind ( function ( req , res , next ) {
1182
1182
1183
+ function internalRemove ( doc ) {
1184
+ doc . remove ( function ( err ) {
1185
+ if ( err ) {
1186
+ return res . send ( { success : false } ) ;
1187
+ }
1188
+ return res . send ( { success : true } ) ;
1189
+ } ) ;
1190
+ }
1191
+
1183
1192
this . processEntity ( req , res , function ( ) {
1184
1193
if ( ! req . resource ) {
1185
1194
next ( ) ;
1186
1195
return ;
1187
1196
}
1188
1197
1189
- req . doc . remove ( function ( err ) {
1190
- if ( err ) {
1191
- return res . send ( { success : false } ) ;
1192
- }
1193
- return res . send ( { success : true } ) ;
1194
- } ) ;
1198
+ let doc = req . doc ;
1199
+ if ( typeof req . resource . options . onRemove === 'function' ) {
1200
+
1201
+ req . resource . options . onRemove ( doc , req , function ( err ) {
1202
+ if ( err ) {
1203
+ throw err ;
1204
+ }
1205
+ internalRemove ( doc ) ;
1206
+ } ) ;
1207
+ } else {
1208
+ internalRemove ( doc ) ;
1209
+ }
1210
+
1195
1211
} ) ;
1196
1212
} , this ) ;
1197
1213
} ;
You can’t perform that action at this time.
0 commit comments