Merge pull request #25 from ha-dai/patch-a

Improve convenience.
This commit is contained in:
syuilo⭐️ 2017-01-05 22:13:01 +09:00 committed by GitHub
commit da7c98ff3f

View File

@ -20,8 +20,18 @@ module.exports = (params, me) =>
{ {
// Get 'user_id' parameter // Get 'user_id' parameter
const userId = params.user_id; const userId = params.user_id;
if (userId === undefined || userId === null) { if (userId === undefined || userId === null || userId === '') {
return rej('user_id is required'); 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 // Get 'with_replies' parameter
@ -62,9 +72,9 @@ module.exports = (params, me) =>
} }
// Lookup user // Lookup user
const user = await User.findOne({ const user = userId !== null
_id: new mongo.ObjectID(userId) ? await User.findOne({ _id: new mongo.ObjectID(userId) })
}); : await User.findOne({ username_lower: username.toLowerCase() });
if (user === null) { if (user === null) {
return rej('user not found'); return rej('user not found');