@@ -740,9 +740,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
740
740
. then ( response => {
741
741
response . updatedAt = this . updatedAt ;
742
742
if ( this . storage . changedByTrigger ) {
743
- Object . keys ( this . data ) . forEach ( fieldName => {
744
- response [ fieldName ] = response [ fieldName ] || this . data [ fieldName ] ;
745
- } ) ;
743
+ updateResponseWithData ( response , this . data ) ;
746
744
}
747
745
this . response = { response } ;
748
746
} ) ;
@@ -766,9 +764,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
766
764
response . objectId = this . data . objectId ;
767
765
response . createdAt = this . data . createdAt ;
768
766
if ( this . storage . changedByTrigger ) {
769
- Object . keys ( this . data ) . forEach ( fieldName => {
770
- response [ fieldName ] = response [ fieldName ] || this . data [ fieldName ] ;
771
- } ) ;
767
+ updateResponseWithData ( response , this . data ) ;
772
768
}
773
769
this . response = {
774
770
status : 201 ,
@@ -857,5 +853,18 @@ RestWrite.prototype.cleanUserAuthData = function() {
857
853
}
858
854
} ;
859
855
856
+ function updateResponseWithData ( response , data ) {
857
+ Object . keys ( data ) . forEach ( fieldName => {
858
+ let dataValue = data [ fieldName ] ;
859
+ let responseValue = response [ fieldName ] ;
860
+ if ( dataValue && dataValue . __op === 'Delete' ) {
861
+ delete response [ fieldName ] ;
862
+ } else {
863
+ response [ fieldName ] = responseValue || dataValue ;
864
+ }
865
+ } ) ;
866
+ return response ;
867
+ }
868
+
860
869
export default RestWrite ;
861
870
module . exports = RestWrite ;
0 commit comments