Skip to content

Commit

Permalink
Fixes #1840
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed May 29, 2016
1 parent 8150f63 commit 9b5761c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
.then(response => {
response.updatedAt = this.updatedAt;
if (this.storage.changedByTrigger) {
Object.keys(this.data).forEach(fieldName => {
response[fieldName] = response[fieldName] || this.data[fieldName];
});
updateResponseWithData(response, this.data);
}
this.response = { response };
});
Expand All @@ -766,9 +764,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
response.objectId = this.data.objectId;
response.createdAt = this.data.createdAt;
if (this.storage.changedByTrigger) {
Object.keys(this.data).forEach(fieldName => {
response[fieldName] = response[fieldName] || this.data[fieldName];
});
updateResponseWithData(response, this.data);
}
this.response = {
status: 201,
Expand Down Expand Up @@ -857,5 +853,18 @@ RestWrite.prototype.cleanUserAuthData = function() {
}
};

function updateResponseWithData(response, data) {
Object.keys(data).forEach(fieldName => {
let dataValue = data[fieldName];
let responseValue = response[fieldName];
if (dataValue && dataValue.__op === 'Delete') {
delete response[fieldName];
} else {
response[fieldName] = responseValue || dataValue;
}
});
return response;
}

export default RestWrite;
module.exports = RestWrite;

0 comments on commit 9b5761c

Please sign in to comment.