summaryrefslogtreecommitdiff
path: root/packages/backend/src/misc/count-same-renotes.ts
blob: 6628761182b29f6a982631552461811c9ae3b089 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { Notes } from '@/models/index';

export async function countSameRenotes(userId: string, renoteId: string, excludeNoteId: string | undefined): Promise<number> {
	// 指定したユーザーの指定したノートのリノートがいくつあるか数える
	const query = Notes.createQueryBuilder('note')
		.where('note.userId = :userId', { userId })
		.andWhere('note.renoteId = :renoteId', { renoteId });

	// 指定した投稿を除く
	if (excludeNoteId) {
		query.andWhere('note.id != :excludeNoteId', { excludeNoteId });
	}

	return await query.getCount();
}