Skip to content

Commit

Permalink
adds user/about
Browse files Browse the repository at this point in the history
  • Loading branch information
Berkeley Martinez authored and Berkeley Martinez committed Jul 29, 2015
1 parent c82b2e3 commit 9e22122
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
50 changes: 49 additions & 1 deletion common/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'
}
}
);
};
11 changes: 7 additions & 4 deletions common/models/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@
"resetPasswordToken": {
"type": "string"
},
"sentSlackInvite": {
"type": "boolean",
"default": false
},
"resetPasswordExpires": {
"type": "string"
},
Expand Down Expand Up @@ -249,6 +245,13 @@
"principalId": "$everyone",
"permission": "ALLOW",
"property": "doesExist"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "about"
}
],
"methods": []
Expand Down

0 comments on commit 9e22122

Please sign in to comment.