misskey/packages/backend/src/server/api/endpoints/admin/update-user-note.ts
2023-06-04 14:48:23 +00:00

30 lines
881 B
TypeScript

import { Inject, Injectable } from '@nestjs/common';
import type { UserProfilesRepository, UsersRepository } from '@/models/index.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { DI } from '@/di-symbols.js';
// eslint-disable-next-line import/no-default-export
@Injectable()
export default class extends Endpoint<'admin/update-user-note'> {
name = 'admin/update-user-note' as const;
constructor(
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,
@Inject(DI.userProfilesRepository)
private userProfilesRepository: UserProfilesRepository,
) {
super(async (ps, me) => {
const user = await this.usersRepository.findOneBy({ id: ps.userId });
if (user == null) {
throw new Error('user not found');
}
await this.userProfilesRepository.update({ userId: user.id }, {
moderationNote: ps.text,
});
});
}
}