isSetMember returns true or false

v1.18.x
Baris Soner Usakli 11 years ago
parent cfd3a7d126
commit 4b5988c269

@ -4,6 +4,7 @@
'use strict';
var mongoClient = require('mongodb').MongoClient,
winston = require('winston'),
async = require('async'),
nconf = require('nconf'),
express = require('express'),
mongoStore = require('connect-mongo')(express),
@ -279,7 +280,17 @@
}
module.isMemberOfSets = function(sets, value, callback) {
throw new Error('not-implemented');
function iterator(set, next) {
module.isSetMember(set, value, next);
}
async.map(sets, iterator, function(err, result) {
console.log(err, result);
callback(err, result);
});
}
module.getSetMembers = function(key, callback) {
@ -469,15 +480,15 @@
}
db.collection('objects').findOne({_key:key}, { array: { $slice: [start, stop - start + 1] }}, function(err, data) {
if(err) {
return callback(err);
}
if(data && data.array) {
callback(null, data.array);
} else {
callback(null, []);
}
});
if(err) {
return callback(err);
}
if(data && data.array) {
callback(null, data.array);
} else {
callback(null, []);
}
});
}

@ -234,7 +234,13 @@
}
module.isSetMember = function(key, value, callback) {
redisClient.sismember(key, value, callback);
redisClient.sismember(key, value, function(err, result) {
if(err) {
return callback(err);
}
callback(null, result === 1);
});
}
module.isMemberOfSets = function(sets, value, callback) {

@ -261,6 +261,13 @@ var DebugRoute = function(app) {
});
}
function isMemberOfSets(callback) {
db.isMemberOfSets(['doesntexist', 'myTestSet', 'nonexistingSet'], 5, function(err, data) {
console.log('isMemberOfSets return', data);
callback(err, {'isMemberOfSets': data});
});
}
function setRemoveRandom(callback) {
db.setRemoveRandom('myTestSet', function(err, data) {
console.log('setRemoveRandom return', data);
@ -317,16 +324,11 @@ var DebugRoute = function(app) {
var setTasks = [
getSetMembers,
// setRemove,
setAdd,
setAdd,
getSetMembers,
isSetMember,
// setRemove,
isSetMember,
getSetMembers,
setRemoveRandom,
getSetMembers
isMemberOfSets
];
require('async').series(setTasks, function(err, results) {

@ -22,7 +22,7 @@ var db = require('./database'),
callback(false);
}
callback( !! ismember || false);
callback(ismember);
});
}

@ -581,9 +581,9 @@ var bcrypt = require('bcrypt'),
};
User.isFollowing = function(uid, theirid, callback) {
db.isSetMember('following:' + uid, theirid, function(err, data) {
db.isSetMember('following:' + uid, theirid, function(err, isMember) {
if (!err) {
callback(data === 1);
callback(isMember);
} else {
console.log(err);
}
@ -695,14 +695,14 @@ var bcrypt = require('bcrypt'),
if(err) {
return calback(err);
}
callback(err, !! exists);
callback(err, exists);
});
};
User.isAdministrator = function(uid, callback) {
groups.getGidFromName('Administrators', function(err, gid) {
groups.isMember(uid, gid, function(err, isAdmin) {
callback(err, !! isAdmin);
callback(err, isAdmin);
});
});
};

Loading…
Cancel
Save