summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints/admin/show-user.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-11-12 02:02:25 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-11-12 02:02:25 +0900
commit0e4a111f81cceed275d9bec2695f6e401fb654d8 (patch)
tree40874799472fa07416f17b50a398ac33b7771905 /packages/backend/src/server/api/endpoints/admin/show-user.ts
parentupdate deps (diff)
downloadsharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.gz
sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.bz2
sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.zip
refactoring
Resolve #7779
Diffstat (limited to 'packages/backend/src/server/api/endpoints/admin/show-user.ts')
-rw-r--r--packages/backend/src/server/api/endpoints/admin/show-user.ts177
1 files changed, 177 insertions, 0 deletions
diff --git a/packages/backend/src/server/api/endpoints/admin/show-user.ts b/packages/backend/src/server/api/endpoints/admin/show-user.ts
new file mode 100644
index 0000000000..963c123255
--- /dev/null
+++ b/packages/backend/src/server/api/endpoints/admin/show-user.ts
@@ -0,0 +1,177 @@
+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 as const,
+ requireModerator: true,
+
+ params: {
+ userId: {
+ validator: $.type(ID),
+ },
+ },
+
+ res: {
+ type: 'object' as const,
+ nullable: false as const, optional: false as const,
+ properties: {
+ id: {
+ type: 'string' as const,
+ nullable: false as const, optional: false as const,
+ format: 'id'
+ },
+ createdAt: {
+ type: 'string' as const,
+ nullable: false as const, optional: false as const,
+ format: 'date-time'
+ },
+ updatedAt: {
+ type: 'string' as const,
+ nullable: true as const, optional: false as const,
+ format: 'date-time'
+ },
+ lastFetchedAt: {
+ type: 'string' as const,
+ nullable: true as const, optional: false as const
+ },
+ username: {
+ type: 'string' as const,
+ nullable: false as const, optional: false as const
+ },
+ name: {
+ type: 'string' as const,
+ nullable: false as const, optional: false as const
+ },
+ folowersCount: {
+ type: 'number' as const,
+ nullable: false as const, optional: false as const
+ },
+ followingCount: {
+ type: 'number' as const,
+ nullable: false as const, optional: false as const
+ },
+ notesCount: {
+ type: 'number' as const,
+ nullable: false as const, optional: false as const
+ },
+ avatarId: {
+ type: 'string' as const,
+ nullable: true as const, optional: false as const
+ },
+ bannerId: {
+ type: 'string' as const,
+ nullable: true as const, optional: false as const
+ },
+ tags: {
+ type: 'array' as const,
+ nullable: false as const, optional: false as const,
+ items: {
+ type: 'string' as const,
+ nullable: false as const, optional: false as const
+ }
+ },
+ avatarUrl: {
+ type: 'string' as const,
+ nullable: true as const, optional: false as const,
+ format: 'url'
+ },
+ bannerUrl: {
+ type: 'string' as const,
+ nullable: true as const, optional: false as const,
+ format: 'url'
+ },
+ avatarBlurhash: {
+ type: 'any' as const,
+ nullable: true as const, optional: false as const,
+ default: null
+ },
+ bannerBlurhash: {
+ type: 'any' as const,
+ nullable: true as const, optional: false as const,
+ default: null
+ },
+ isSuspended: {
+ type: 'boolean' as const,
+ nullable: false as const, optional: false as const
+ },
+ isSilenced: {
+ type: 'boolean' as const,
+ nullable: false as const, optional: false as const
+ },
+ isLocked: {
+ type: 'boolean' as const,
+ nullable: false as const, optional: false as const,
+ },
+ isBot: {
+ type: 'boolean' as const,
+ nullable: false as const, optional: false as const
+ },
+ isCat: {
+ type: 'boolean' as const,
+ nullable: false as const, optional: false as const
+ },
+ isAdmin: {
+ type: 'boolean' as const,
+ nullable: false as const, optional: false as const
+ },
+ isModerator: {
+ type: 'boolean' as const,
+ nullable: false as const, optional: false as const
+ },
+ emojis: {
+ type: 'array' as const,
+ nullable: false as const, optional: false as const,
+ items: {
+ type: 'string' as const,
+ nullable: false as const, optional: false as const
+ }
+ },
+ host: {
+ type: 'string' as const,
+ nullable: true as const, optional: false as const
+ },
+ inbox: {
+ type: 'string' as const,
+ nullable: true as const, optional: false as const
+ },
+ sharedInbox: {
+ type: 'string' as const,
+ nullable: true as const, optional: false as const
+ },
+ featured: {
+ type: 'string' as const,
+ nullable: true as const, optional: false as const
+ },
+ uri: {
+ type: 'string' as const,
+ nullable: true as const, optional: false as const
+ },
+ token: {
+ type: 'string' as const,
+ nullable: false as const, optional: false as const,
+ default: '<MASKED>'
+ }
+ }
+ }
+};
+
+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,
+ };
+});