mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
closes #6340
This commit is contained in:
@@ -66,7 +66,21 @@ module.exports = function (db, module) {
|
||||
if (!key) {
|
||||
return callback();
|
||||
}
|
||||
module.getObjectField(key, 'data', callback);
|
||||
module.getObject(key, function (err, objectData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
// fallback to old field name 'value' for backwards compatibility #6340
|
||||
var value = null;
|
||||
if (objectData) {
|
||||
if (objectData.hasOwnProperty('data')) {
|
||||
value = objectData.data;
|
||||
} else if (objectData.hasOwnProperty('value')) {
|
||||
value = objectData.value;
|
||||
}
|
||||
}
|
||||
callback(null, value);
|
||||
});
|
||||
};
|
||||
|
||||
module.set = function (key, value, callback) {
|
||||
|
||||
@@ -27,6 +27,14 @@ describe('Key methods', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return null if key does not exist', function (done) {
|
||||
db.get('doesnotexist', function (err, value) {
|
||||
assert.ifError(err);
|
||||
assert.equal(value, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true if key exist', function (done) {
|
||||
db.exists('testKey', function (err, exists) {
|
||||
assert.ifError(err);
|
||||
|
||||
Reference in New Issue
Block a user