Skip to content

Commit 9b5761c

Browse files
committed
Fixes #1840
1 parent 8150f63 commit 9b5761c

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/RestWrite.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -740,9 +740,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
740740
.then(response => {
741741
response.updatedAt = this.updatedAt;
742742
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);
746744
}
747745
this.response = { response };
748746
});
@@ -766,9 +764,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
766764
response.objectId = this.data.objectId;
767765
response.createdAt = this.data.createdAt;
768766
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);
772768
}
773769
this.response = {
774770
status: 201,
@@ -857,5 +853,18 @@ RestWrite.prototype.cleanUserAuthData = function() {
857853
}
858854
};
859855

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+
860869
export default RestWrite;
861870
module.exports = RestWrite;

0 commit comments

Comments
 (0)