From e72a29b3fda8ad879a7b03450d13b991a911bba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 24 Feb 2020 18:07:51 -0500 Subject: [PATCH] fix: return null if field does not exist --- src/meta/settings.js | 3 +-- test/meta.js | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/meta/settings.js b/src/meta/settings.js index 17ae969043..a5cc59bbe3 100644 --- a/src/meta/settings.js +++ b/src/meta/settings.js @@ -11,7 +11,6 @@ Settings.get = async function (hash) { const data = await db.getObject('settings:' + hash) || {}; const sortedLists = await db.getSetMembers('settings:' + hash + ':sorted-lists'); - await Promise.all(sortedLists.map(async function (list) { const members = await db.getSortedSetRange('settings:' + hash + ':sorted-list:' + list, 0, -1) || []; const keys = []; @@ -32,7 +31,7 @@ Settings.get = async function (hash) { Settings.getOne = async function (hash, field) { const data = await Settings.get(hash); - return data[field]; + return data[field] !== undefined ? data[field] : null; }; Settings.set = async function (hash, values, quiet) { diff --git a/test/meta.js b/test/meta.js index 097fb7480e..04c1bd0000 100644 --- a/test/meta.js +++ b/test/meta.js @@ -94,6 +94,11 @@ describe('meta', function () { }); }); + it('should return null if setting field does not exist', async function () { + const val = await meta.settings.getOne('some:hash', 'does not exist'); + assert.strictEqual(val, null); + }); + const someList = [ { name: 'andrew', status: 'best' }, { name: 'baris', status: 'wurst' },