mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: api: allow extend
This commit is contained in:
1 parent
97b262f997
commit
9eece289e0
3 files changed
+96
-21
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import moment from 'moment-timezone';
|
||||
import { registerResolver, registerValue } from './api';
|
||||
import {
|
||||
UserAlreadyExistError, InvalidTokenError, VerifyPasswordError,
|
||||
UserNotFoundError, SystemError, BlacklistedError,
|
||||
@@ -22,6 +23,34 @@ import { sendMail } from '../lib/mail';
|
||||
import paginate from '../lib/paginate';
|
||||
import avatar from '../lib/avatar';
|
||||
|
||||
registerValue('User', [
|
||||
['_id', 'Int!'],
|
||||
['uname', 'String!'],
|
||||
['mail', 'String!'],
|
||||
['perm', 'Int'],
|
||||
['scope', 'Int'],
|
||||
['role', 'String'],
|
||||
['loginat', 'Date'],
|
||||
['regat', 'Date'],
|
||||
['priv', 'Int', 'User Privilege'],
|
||||
]);
|
||||
|
||||
registerResolver('Query', 'user(id: Int, uname: String, mail: String)', 'User', (arg, ctx) => {
|
||||
if (arg.id) return user.getById(ctx.domainId, arg.id);
|
||||
if (arg.mail) return user.getByEmail(ctx.domainId, arg.mail);
|
||||
if (arg.uname) return user.getByUname(ctx.domainId, arg.uname);
|
||||
return ctx.user;
|
||||
}, `Get a user by id, uname, or mail.
|
||||
Returns current user if no argument is provided.`);
|
||||
|
||||
registerResolver('Query', 'users(ids: [Int], search: String)', '[User]', async (arg, ctx) => {
|
||||
if (arg.ids) {
|
||||
const res = await user.getList(ctx.domainId, arg.ids);
|
||||
return Object.keys(res).map((id) => res[+id]);
|
||||
}
|
||||
return arg.search ? await user.getPrefixList(ctx.domainId, arg.search) : [];
|
||||
}, 'Get a list of user by ids, or search users with the prefix.');
|
||||
|
||||
class UserLoginHandler extends Handler {
|
||||
noCheckPermView = true;
|
||||
|
||||
|
||||
Reference in new issue
Block a user