forked from FoundKeyGang/FoundKey
Johann150
7b8333a21f
Instead of throwing an IdentifiableError which then just always gets converted into an ApiError, the getter can just throw the same ApiError directly. This makes it more convenient to use and thus more endpoints have been refactored to use it to reduce code repetition.
43 lines
1 KiB
TypeScript
43 lines
1 KiB
TypeScript
import { Users } from '@/models/index.js';
|
|
import { ApiError } from '@/server/api/error.js';
|
|
import { insertModerationLog } from '@/services/insert-moderation-log.js';
|
|
import { publishInternalEvent } from '@/services/stream.js';
|
|
import define from '@/server/api/define.js';
|
|
import { getUser } from '@/server/api/common/getters.js';
|
|
|
|
export const meta = {
|
|
tags: ['admin'],
|
|
|
|
requireCredential: true,
|
|
requireModerator: true,
|
|
|
|
errors: ['NO_SUCH_USER', 'IS_ADMIN'],
|
|
} as const;
|
|
|
|
export const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
userId: { type: 'string', format: 'misskey:id' },
|
|
},
|
|
required: ['userId'],
|
|
} as const;
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
export default define(meta, paramDef, async (ps, me) => {
|
|
const user = await getUser(ps.userId);
|
|
|
|
if (user.isAdmin) {
|
|
throw new ApiError('IS_ADMIN');
|
|
}
|
|
|
|
await Users.update(user.id, {
|
|
isSilenced: true,
|
|
});
|
|
|
|
publishInternalEvent('userChangeSilencedState', { id: user.id, isSilenced: true });
|
|
|
|
insertModerationLog(me, 'silence', {
|
|
targetId: user.id,
|
|
});
|
|
});
|