2021-08-19 12:33:41 +03:00
|
|
|
import { Notes } from '@/models/index.js';
|
2020-02-26 00:54:35 +02:00
|
|
|
|
2020-02-26 00:56:32 +02:00
|
|
|
export async function countSameRenotes(userId: string, renoteId: string, excludeNoteId: string | undefined): Promise<number> {
|
2020-02-26 00:54:35 +02:00
|
|
|
// 指定したユーザーの指定したノートのリノートがいくつあるか数える
|
|
|
|
const query = Notes.createQueryBuilder('note')
|
|
|
|
.where('note.userId = :userId', { userId })
|
2020-05-10 11:25:16 +03:00
|
|
|
.andWhere('note.renoteId = :renoteId', { renoteId });
|
2020-02-26 00:54:35 +02:00
|
|
|
|
|
|
|
// 指定した投稿を除く
|
|
|
|
if (excludeNoteId) {
|
2020-05-10 11:25:16 +03:00
|
|
|
query.andWhere('note.id != :excludeNoteId', { excludeNoteId });
|
2020-02-26 00:54:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return await query.getCount();
|
|
|
|
}
|