mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-13 13:37:31 -07:00
Improve convenience.
This commit is contained in:
parent
a9628ad0fb
commit
f15c862491
1 changed files with 15 additions and 5 deletions
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue