From da7e95f426631cf6449722e4ee70714cf6b41d38 Mon Sep 17 00:00:00 2001 From: Mejituu Date: Tue, 10 Oct 2023 23:00:06 +0800 Subject: [PATCH] Fix: TypeError: Cannot use 'in' operator to search for 'updatedAt' in undefined (#2113) * Fix: TypeError: Cannot use 'in' operator to search for 'updatedAt' in undefined Revert: Remove 'updateAt' property in leancloud update. (#2108) * chore: use for...in replace hasOwnProperty --------- Co-authored-by: Austin Lee --- .../server/src/service/storage/leancloud.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/server/src/service/storage/leancloud.js b/packages/server/src/service/storage/leancloud.js index 063a7693147..0d390d8191c 100644 --- a/packages/server/src/service/storage/leancloud.js +++ b/packages/server/src/service/storage/leancloud.js @@ -405,15 +405,16 @@ module.exports = class extends Base { ret.map(async (item) => { const _oldStatus = item.get('status'); - var newData - if (think.isFunction(data)) { - newData = data(item.toJSON()) - } - if ('updatedAt' in newData) { - delete newData.updatedAt - } - item.set(newData) + var updateData = typeof data === 'function' ? data(item.toJSON()) : data; + const REVERSED_KEYS = ['createdAt', 'updatedAt']; + for (const k in updateData) { + if (REVERSED_KEYS.includes(k)) { + continue; + } + instance.set(k, updateData[k]); + } + const _newStatus = item.get('status'); if (_newStatus && _oldStatus !== _newStatus) {