@@ -736,9 +736,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
736
736
. then ( response => {
737
737
response . updatedAt = this . updatedAt ;
738
738
if ( this . storage . changedByTrigger ) {
739
- Object . keys ( this . data ) . forEach ( fieldName => {
740
- response [ fieldName ] = response [ fieldName ] || this . data [ fieldName ] ;
741
- } ) ;
739
+ updateResponseWithData ( response , this . data ) ;
742
740
}
743
741
this . response = { response } ;
744
742
} ) ;
@@ -796,9 +794,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
796
794
response . username = this . data . username ;
797
795
}
798
796
if ( this . storage . changedByTrigger ) {
799
- Object . keys ( this . data ) . forEach ( fieldName => {
800
- response [ fieldName ] = response [ fieldName ] || this . data [ fieldName ] ;
801
- } ) ;
797
+ updateResponseWithData ( response , this . data ) ;
802
798
}
803
799
this . response = {
804
800
status : 201 ,
@@ -887,5 +883,18 @@ RestWrite.prototype.cleanUserAuthData = function() {
887
883
}
888
884
} ;
889
885
886
+ function updateResponseWithData ( response , data ) {
887
+ Object . keys ( data ) . forEach ( fieldName => {
888
+ let dataValue = data [ fieldName ] ;
889
+ let responseValue = response [ fieldName ] ;
890
+ if ( dataValue && dataValue . __op === 'Delete' ) {
891
+ delete response [ fieldName ] ;
892
+ } else {
893
+ response [ fieldName ] = responseValue || dataValue ;
894
+ }
895
+ } ) ;
896
+ return response ;
897
+ }
898
+
890
899
export default RestWrite ;
891
900
module . exports = RestWrite ;
0 commit comments