adds user/about

This commit is contained in:
Berkeley Martinez
2015-07-29 11:32:16 -07:00
parent c82b2e3ae6
commit 9e22122832
2 changed files with 56 additions and 5 deletions

View File

@ -93,7 +93,7 @@ module.exports = function(User) {
debug('where', where);
User.count(
where,
function (err, count) {
function(err, count) {
if (err) {
debug('err checking existance: ', err);
return cb(err);
@ -132,4 +132,52 @@ module.exports = function(User) {
}
}
);
User.about = function about(username, cb) {
if (!username) {
// Zalgo!!
return process.nextTick(() => {
cb(
new TypeError('FCC: username should be a string but got %s', username)
);
});
}
User.findOne({ where: { username } }, (err, user) => {
if (err) {
cb(err);
}
if (!user || user.username !== username) {
cb(new Error('FCC: no user found for %s', username));
}
const aboutUser = {
username: user.username,
bio: user.bio,
github: user.githubProfile
};
cb(null, aboutUser);
});
};
User.remoteMethod(
'about',
{
description: 'get public info about user',
accepts: [
{
arg: 'username',
type: 'string'
}
],
returns: [
{
arg: 'about',
type: 'object'
}
],
http: {
path: '/about',
verb: 'get'
}
}
);
};