2022-02-27 02:07:39 +00:00
|
|
|
import { Users } from '@/models/index.js';
|
2022-12-25 14:33:46 +00:00
|
|
|
import { ApiError } from '@/server/api/error.js';
|
2023-01-07 18:28:18 +00:00
|
|
|
import { deleteAccount } from '@/services/delete-account.js';
|
2022-08-03 11:18:33 +00:00
|
|
|
import define from '../../../define.js';
|
2021-09-22 08:34:48 +00:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['admin'],
|
|
|
|
|
2022-01-18 13:27:10 +00:00
|
|
|
requireCredential: true,
|
2023-01-07 18:30:06 +00:00
|
|
|
requireAdmin: true,
|
2022-12-25 14:33:46 +00:00
|
|
|
|
|
|
|
errors: ['NO_SUCH_USER', 'IS_ADMIN', 'IS_MODERATOR'],
|
2022-02-19 05:05:32 +00:00
|
|
|
} as const;
|
2021-09-22 08:34:48 +00:00
|
|
|
|
2022-02-20 04:15:40 +00:00
|
|
|
export const paramDef = {
|
2022-02-19 05:05:32 +00:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
userId: { type: 'string', format: 'misskey:id' },
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
2022-02-19 05:05:32 +00:00
|
|
|
required: ['userId'],
|
2022-01-18 13:27:10 +00:00
|
|
|
} as const;
|
2021-09-22 08:34:48 +00:00
|
|
|
|
2022-01-02 17:12:50 +00:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2023-01-03 02:51:38 +00:00
|
|
|
export default define(meta, paramDef, async (ps) => {
|
2023-01-07 18:28:18 +00:00
|
|
|
const user = await Users.findOneBy({
|
|
|
|
id: ps.userId,
|
|
|
|
isDeleted: false,
|
|
|
|
});
|
2021-09-22 08:34:48 +00:00
|
|
|
|
|
|
|
if (user == null) {
|
2022-12-25 14:33:46 +00:00
|
|
|
throw new ApiError('NO_SUCH_USER');
|
|
|
|
} else if (user.isAdmin) {
|
|
|
|
throw new ApiError('IS_ADMIN');
|
2023-01-03 02:51:38 +00:00
|
|
|
} else if (user.isModerator) {
|
2022-12-25 14:33:46 +00:00
|
|
|
throw new ApiError('IS_MODERATOR');
|
2021-09-22 08:34:48 +00:00
|
|
|
}
|
|
|
|
|
2023-01-07 18:28:18 +00:00
|
|
|
await deleteAccount(user);
|
2021-09-22 08:34:48 +00:00
|
|
|
});
|