2023-01-12 21:40:33 -07:00
|
|
|
import { Notes } from "@/models/index.js";
|
2020-02-25 15:54:35 -07:00
|
|
|
|
2023-01-12 21:40:33 -07:00
|
|
|
export async function countSameRenotes(
|
|
|
|
userId: string,
|
|
|
|
renoteId: string,
|
|
|
|
excludeNoteId: string | undefined,
|
|
|
|
): Promise<number> {
|
2020-02-25 15:54:35 -07:00
|
|
|
// 指定したユーザーの指定したノートのリノートがいくつあるか数える
|
2023-01-12 21:40:33 -07:00
|
|
|
const query = Notes.createQueryBuilder("note")
|
|
|
|
.where("note.userId = :userId", { userId })
|
|
|
|
.andWhere("note.renoteId = :renoteId", { renoteId });
|
2020-02-25 15:54:35 -07:00
|
|
|
|
|
|
|
// 指定した投稿を除く
|
|
|
|
if (excludeNoteId) {
|
2023-01-12 21:40:33 -07:00
|
|
|
query.andWhere("note.id != :excludeNoteId", { excludeNoteId });
|
2020-02-25 15:54:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return await query.getCount();
|
|
|
|
}
|