Skip to content

Instantly share code, notes, and snippets.

@milanvanschaik
Created May 22, 2014 20:47
Show Gist options
  • Save milanvanschaik/1bd3bb933707a51d5cd0 to your computer and use it in GitHub Desktop.
Save milanvanschaik/1bd3bb933707a51d5cd0 to your computer and use it in GitHub Desktop.
var Bucket = require('./couchbase/bucket');
/**
* Manage users
* @static
* @class users
*/
var users = module.exports = {};
(function(users) {
'use strict';
/**
* Create bucket functions for this object
* @type {Bucket}
* @property {bucket}
*/
var bucket = users.bucket = new Bucket('users');
/**
* Clean up the results from Couchbase
* @method cleanResult
* @param {result} input
*/
users.cleanResult = function cleanResult(input) {
return Object.keys(input).map(function(index) {
delete input[index].flags;
return input[index];
});
};
/**
* Get one or multiple users by id
* @method getById
* @param {user_id} ids (string or array)
* @param {function} callback
*/
users.getById = function(ids, callback) {
bucket.getMulti(ids, {}, function(error, result) {
if(error) {
callback();
}
var res = users.cleanResult(result).map(function(res) { return res.value; });
return callback(res);
});
};
/**
* Create a new user
* @method create
* @param {user} data
* @param {function} callback
*/
users.create = function(data, callback) {
//
};
})(users);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment