jormungandr-bite/packages/backend/src/misc/count-same-renotes.ts
ThatOneCalculator 2aab2de38d refactor: 🎨 rome
2023-01-12 20:40:33 -08:00

19 lines
584 B
TypeScript

import { Notes } from "@/models/index.js";
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();
}