33 lines
786 B
JavaScript
33 lines
786 B
JavaScript
|
var users = require('./users');
|
||
|
|
||
|
exports.findById = function(id, cb) {
|
||
|
process.nextTick(function() {
|
||
|
var idx = id - 1;
|
||
|
if (users.records[idx]) {
|
||
|
cb(null, users.records[idx]);
|
||
|
} else {
|
||
|
cb(new Error('User ' + id + ' does not exist'));
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
exports.findByUsername = function(username, cb) {
|
||
|
process.nextTick(function() {
|
||
|
for (var i = 0, len = users.records.length; i < len; i++) {
|
||
|
var record = users.records[i];
|
||
|
if (record.username === username) {
|
||
|
return cb(null, record);
|
||
|
}
|
||
|
}
|
||
|
return cb(null, null);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
exports.userIdArray = function() {
|
||
|
var userIdArray = [];
|
||
|
for (var i = 0, len = users.records.length; i < len; i++) {
|
||
|
userIdArray.push(users.records[i].id);
|
||
|
}
|
||
|
return userIdArray;
|
||
|
}
|