Skip to content

Commit 85d011e

Browse files
committed
Fixes #1840
1 parent 45211a6 commit 85d011e

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/RestWrite.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
736736
.then(response => {
737737
response.updatedAt = this.updatedAt;
738738
if (this.storage.changedByTrigger) {
739-
Object.keys(this.data).forEach(fieldName => {
740-
response[fieldName] = response[fieldName] || this.data[fieldName];
741-
});
739+
updateResponseWithData(response, this.data);
742740
}
743741
this.response = { response };
744742
});
@@ -796,9 +794,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
796794
response.username = this.data.username;
797795
}
798796
if (this.storage.changedByTrigger) {
799-
Object.keys(this.data).forEach(fieldName => {
800-
response[fieldName] = response[fieldName] || this.data[fieldName];
801-
});
797+
updateResponseWithData(response, this.data);
802798
}
803799
this.response = {
804800
status: 201,
@@ -887,5 +883,18 @@ RestWrite.prototype.cleanUserAuthData = function() {
887883
}
888884
};
889885

886+
function updateResponseWithData(response, data) {
887+
Object.keys(data).forEach(fieldName => {
888+
let dataValue = data[fieldName];
889+
let responseValue = response[fieldName];
890+
if (dataValue && dataValue.__op === 'Delete') {
891+
delete response[fieldName];
892+
} else {
893+
response[fieldName] = responseValue || dataValue;
894+
}
895+
});
896+
return response;
897+
}
898+
890899
export default RestWrite;
891900
module.exports = RestWrite;

0 commit comments

Comments
 (0)