Skip to content

Commit eb9ee1a

Browse files
committed
Fixes #1840
1 parent a2a5105 commit eb9ee1a

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
@@ -763,9 +763,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
763763
.then(response => {
764764
response.updatedAt = this.updatedAt;
765765
if (this.storage.changedByTrigger) {
766-
Object.keys(this.data).forEach(fieldName => {
767-
response[fieldName] = response[fieldName] || this.data[fieldName];
768-
});
766+
updateResponseWithData(response, this.data);
769767
}
770768
this.response = { response };
771769
});
@@ -823,9 +821,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
823821
response.username = this.data.username;
824822
}
825823
if (this.storage.changedByTrigger) {
826-
Object.keys(this.data).forEach(fieldName => {
827-
response[fieldName] = response[fieldName] || this.data[fieldName];
828-
});
824+
updateResponseWithData(response, this.data);
829825
}
830826
this.response = {
831827
status: 201,
@@ -914,5 +910,18 @@ RestWrite.prototype.cleanUserAuthData = function() {
914910
}
915911
};
916912

913+
function updateResponseWithData(response, data) {
914+
Object.keys(data).forEach(fieldName => {
915+
let dataValue = data[fieldName];
916+
let responseValue = response[fieldName];
917+
if (dataValue && dataValue.__op === 'Delete') {
918+
delete response[fieldName];
919+
} else {
920+
response[fieldName] = responseValue || dataValue;
921+
}
922+
});
923+
return response;
924+
}
925+
917926
export default RestWrite;
918927
module.exports = RestWrite;

0 commit comments

Comments
 (0)