From 798fb370cf1b3c0e7cdc6d4b943c4c084051127d Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Sun, 29 May 2016 09:23:33 -0400 Subject: [PATCH] Fixes #1840 --- src/RestWrite.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/RestWrite.js b/src/RestWrite.js index bc1ad2c0ae..d773e00050 100644 --- a/src/RestWrite.js +++ b/src/RestWrite.js @@ -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 }; }); @@ -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, @@ -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;