Skip to content

Commit

Permalink
Fixes #1840
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Jul 12, 2016
1 parent dcfc815 commit 798fb37
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 @@ -763,9 +763,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 Down Expand Up @@ -823,9 +821,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
response.username = this.data.username;
}
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 @@ -914,5 +910,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 798fb37

Please sign in to comment.