@@ -763,9 +763,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
763
763
. then ( response => {
764
764
response . updatedAt = this . updatedAt ;
765
765
if ( this . storage . changedByTrigger ) {
766
- Object . keys ( this . data ) . forEach ( fieldName => {
767
- response [ fieldName ] = response [ fieldName ] || this . data [ fieldName ] ;
768
- } ) ;
766
+ updateResponseWithData ( response , this . data ) ;
769
767
}
770
768
this . response = { response } ;
771
769
} ) ;
@@ -823,9 +821,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
823
821
response . username = this . data . username ;
824
822
}
825
823
if ( this . storage . changedByTrigger ) {
826
- Object . keys ( this . data ) . forEach ( fieldName => {
827
- response [ fieldName ] = response [ fieldName ] || this . data [ fieldName ] ;
828
- } ) ;
824
+ updateResponseWithData ( response , this . data ) ;
829
825
}
830
826
this . response = {
831
827
status : 201 ,
@@ -914,5 +910,18 @@ RestWrite.prototype.cleanUserAuthData = function() {
914
910
}
915
911
} ;
916
912
913
+ function updateResponseWithData ( response , data ) {
914
+ Object . keys ( data ) . forEach ( fieldName => {
915
+ let dataValue = data [ fieldName ] ;
916
+ let responseValue = response [ fieldName ] ;
917
+ if ( dataValue && dataValue . __op === 'Delete' ) {
918
+ delete response [ fieldName ] ;
919
+ } else {
920
+ response [ fieldName ] = responseValue || dataValue ;
921
+ }
922
+ } ) ;
923
+ return response ;
924
+ }
925
+
917
926
export default RestWrite ;
918
927
module . exports = RestWrite ;
0 commit comments