monkeeShark/src/server/api/endpoints/admin/show-user.ts
syuilo b9cb6d1c10 refactor: refactoring imports
将来ESMに移行しやすいように
Related: #7658

なんかmochaが起動しなくなってるけど理由不明
すぐ直したい
2021-08-19 18:33:41 +09:00

177 lines
4.2 KiB
TypeScript

import $ from 'cafy';
import { ID } from '@/misc/cafy-id.js';
import define from '../../define.js';
import { Users } from '@/models/index.js';
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,
};
});