Skip to content

Commit

Permalink
fix: return null if field does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Feb 24, 2020
1 parent 14e7866 commit e72a29b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/meta/settings.js
Expand Up @@ -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 = [];
Expand All @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions test/meta.js
Expand Up @@ -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' },
Expand Down

0 comments on commit e72a29b

Please sign in to comment.