@@ -12,6 +12,7 @@ var passwordCrypto = require('./password');
12
12
var Parse = require ( 'parse/node' ) ;
13
13
var triggers = require ( './triggers' ) ;
14
14
import RestQuery from './RestQuery' ;
15
+ import _ from 'lodash' ;
15
16
16
17
// query and data are both provided in REST API format. So data
17
18
// types are encoded by plain old objects.
@@ -165,8 +166,10 @@ RestWrite.prototype.runBeforeTrigger = function() {
165
166
return triggers . maybeRunTrigger ( triggers . Types . beforeSave , this . auth , updatedObject , originalObject , this . config ) ;
166
167
} ) . then ( ( response ) => {
167
168
if ( response && response . object ) {
169
+ if ( ! _ . isEqual ( this . data , response . object ) ) {
170
+ this . storage . changedByTrigger = true ;
171
+ }
168
172
this . data = response . object ;
169
- this . storage [ 'changedByTrigger' ] = true ;
170
173
// We should delete the objectId for an update write
171
174
if ( this . query && this . query . objectId ) {
172
175
delete this . data . objectId
@@ -733,19 +736,16 @@ RestWrite.prototype.runDatabaseOperation = function() {
733
736
this . data . ACL [ this . query . objectId ] = { read : true , write : true } ;
734
737
}
735
738
// Run an update
736
- return this . config . database . update (
737
- this . className , this . query , this . data , this . runOptions ) . then ( ( resp ) => {
738
- resp . updatedAt = this . updatedAt ;
739
- if ( this . storage [ 'changedByTrigger' ] ) {
740
- resp = Object . keys ( this . data ) . reduce ( ( memo , key ) => {
741
- memo [ key ] = resp [ key ] || this . data [ key ] ;
742
- return memo ;
743
- } , resp ) ;
744
- }
745
- this . response = {
746
- response : resp
747
- } ;
748
- } ) ;
739
+ return this . config . database . update ( this . className , this . query , this . data , this . runOptions )
740
+ . then ( response => {
741
+ response . updatedAt = this . updatedAt ;
742
+ if ( this . storage . changedByTrigger ) {
743
+ Object . keys ( this . data ) . forEach ( fieldName => {
744
+ response [ fieldName ] = response [ fieldName ] || this . data [ fieldName ] ;
745
+ } ) ;
746
+ }
747
+ this . response = { response } ;
748
+ } ) ;
749
749
} else {
750
750
// Set the default ACL for the new _User
751
751
if ( this . className === '_User' ) {
@@ -762,23 +762,20 @@ RestWrite.prototype.runDatabaseOperation = function() {
762
762
763
763
// Run a create
764
764
return this . config . database . create ( this . className , this . data , this . runOptions )
765
- . then ( ( resp ) => {
766
- Object . assign ( resp , {
767
- objectId : this . data . objectId ,
768
- createdAt : this . data . createdAt
765
+ . then ( response => {
766
+ response . objectId = this . data . objectId ;
767
+ response . createdAt = this . data . createdAt ;
768
+ if ( this . storage . changedByTrigger ) {
769
+ Object . keys ( this . data ) . forEach ( fieldName => {
770
+ response [ fieldName ] = response [ fieldName ] || this . data [ fieldName ] ;
769
771
} ) ;
770
- if ( this . storage [ 'changedByTrigger' ] ) {
771
- resp = Object . keys ( this . data ) . reduce ( ( memo , key ) => {
772
- memo [ key ] = resp [ key ] || this . data [ key ] ;
773
- return memo ;
774
- } , resp ) ;
775
- }
776
- this . response = {
777
- status : 201 ,
778
- response : resp ,
779
- location : this . location ( )
780
- } ;
781
- } ) ;
772
+ }
773
+ this . response = {
774
+ status : 201 ,
775
+ response,
776
+ location : this . location ( )
777
+ } ;
778
+ } ) ;
782
779
}
783
780
} ;
784
781
0 commit comments