1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-12-27 13:08:15 +09:00
MisskeyIO/packages/backend/src/server/api/endpoints/admin/show-user.ts
2022-02-03 21:09:07 +09:00

41 lines
778 B
TypeScript

import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../define';
import { Users } from '@/models/index';
export const meta = {
tags: ['admin'],
requireCredential: true,
requireModerator: true,
params: {
userId: {
validator: $.type(ID),
},
},
res: {
type: 'object',
nullable: false, optional: false,
},
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps, me) => {
const user = await Users.findOne(ps.userId as string);
if (user == null) {
throw new Error('user not found');
}
if ((me.isModerator && !me.isAdmin) && user.isAdmin) {
throw new Error('cannot show info of admin');
}
return {
...user,
token: user.token != null ? '<MASKED>' : user.token,
};
});