v1.18.x
barisusakli 10 years ago
parent a926a11e70
commit 4c62590bc8

@ -174,6 +174,31 @@ module.exports = function(db, module) {
});
};
module.isObjectFields = function(key, fields, callback) {
if (!key) {
return callback();
}
var data = {};
fields.forEach(function(field) {
field = helpers.fieldToString(field);
data[field] = '';
});
db.collection('objects').findOne({_key: key}, {fields: data}, function(err, item) {
if (err) {
return callback(err);
}
var results = [];
fields.forEach(function(field, index) {
results[index] = !!item && item[field] !== undefined && item[field] !== null;
});
callback(null, results);
});
};
module.deleteObjectField = function(key, field, callback) {
callback = callback || helpers.noop;
if (!key || !field) {

@ -222,7 +222,7 @@ describe('Hash methods', function() {
});
it('should return false if field does not exist', function(done) {
db.isObjectField('testObject1', 'field1', function(err, value) {
db.isObjectField('hashTestObject', 'field1', function(err, value) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(value, false);
@ -240,6 +240,27 @@ describe('Hash methods', function() {
});
});
describe('isObjectFields()', function() {
it('should return an array of false if object does not exist', function(done) {
db.isObjectFields('doesnotexist', ['field1', 'field2'], function(err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, [false, false]);
done();
});
});
it('should return false if field does not exist', function(done) {
db.isObjectFields('hashTestObject', ['name', 'age', 'field1'], function(err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, [true, true, false]);
done();
});
});
});
describe('deleteObjectField()', function() {
before(function(done) {
db.setObject('testObject10', {foo: 'bar', delete: 'this'}, done);

Loading…
Cancel
Save