jormungandr-bite/packages/backend/src/misc/count-same-renotes.ts

20 lines
584 B
TypeScript
Raw Normal View History

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