1
0
mirror of https://github.com/hotomoe/hotomoe synced 2024-12-16 23:58:14 +09:00
hotomoe/packages/backend/src/core/DeleteAccountService.ts

44 lines
1.2 KiB
TypeScript
Raw Normal View History

/*
* SPDX-FileCopyrightText: syuilo and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
2022-09-18 03:27:08 +09:00
import { Inject, Injectable } from '@nestjs/common';
import type { UsersRepository } from '@/models/_.js';
2022-09-18 03:27:08 +09:00
import { QueueService } from '@/core/QueueService.js';
import { UserSuspendService } from '@/core/UserSuspendService.js';
import { DI } from '@/di-symbols.js';
import { bindThis } from '@/decorators.js';
2022-09-18 03:27:08 +09:00
@Injectable()
export class DeleteAccountService {
constructor(
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,
private userSuspendService: UserSuspendService,
private queueService: QueueService,
) {
}
@bindThis
2022-09-18 03:27:08 +09:00
public async deleteAccount(user: {
id: string;
host: string | null;
}): Promise<void> {
const _user = await this.usersRepository.findOneByOrFail({ id: user.id });
if (_user.isRoot) throw new Error('cannot delete a root account');
2022-09-18 03:27:08 +09:00
// 物理削除する前にDelete activityを送信する
await this.userSuspendService.doPostSuspend(user).catch(e => {});
2022-09-18 03:27:08 +09:00
this.queueService.createDeleteAccountJob(user, {
soft: false,
});
2022-09-18 03:27:08 +09:00
await this.usersRepository.update(user.id, {
isDeleted: true,
});
}
}