summaryrefslogtreecommitdiff
path: root/src/api/endpoints/users
diff options
context:
space:
mode:
authorha-dai <contact@haradai.net>2017-01-05 21:58:02 +0900
committerha-dai <contact@haradai.net>2017-01-05 21:58:02 +0900
commit56cb70ee847bd511c5a925dbad3e495f22126c7c (patch)
tree6fa90a032069f86595f7a1b27a264907a0c19bc6 /src/api/endpoints/users
parentUpdate browserify (diff)
downloadsharkey-56cb70ee847bd511c5a925dbad3e495f22126c7c.tar.gz
sharkey-56cb70ee847bd511c5a925dbad3e495f22126c7c.tar.bz2
sharkey-56cb70ee847bd511c5a925dbad3e495f22126c7c.zip
Improve convenience.
Diffstat (limited to 'src/api/endpoints/users')
-rw-r--r--src/api/endpoints/users/posts.js20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/api/endpoints/users/posts.js b/src/api/endpoints/users/posts.js
index 6d6f8a6904..e1a59efa2f 100644
--- a/src/api/endpoints/users/posts.js
+++ b/src/api/endpoints/users/posts.js
@@ -20,8 +20,18 @@ module.exports = (params, me) =>
{
// Get 'user_id' parameter
const userId = params.user_id;
- if (userId === undefined || userId === null) {
- return rej('user_id is required');
+ if (userId === undefined || userId === null || userId === '') {
+ userId = null;
+ }
+
+ // Get 'username' parameter
+ const username = params.username;
+ if (username === undefined || username === null || username === '') {
+ username = null;
+ }
+
+ if (userId === null && username === null) {
+ return rej('user_id or username is required');
}
// Get 'with_replies' parameter
@@ -62,9 +72,9 @@ module.exports = (params, me) =>
}
// Lookup user
- const user = await User.findOne({
- _id: new mongo.ObjectID(userId)
- });
+ const user = userId !== null
+ ? await User.findOne({ _id: new mongo.ObjectID(userId) })
+ : await User.findOne({ username_lower: username.toLowerCase() });
if (user === null) {
return rej('user not found');