From 7121bdef6b232294acda25b169be1e008a8812b6 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 26 Feb 2020 07:56:32 +0900 Subject: Refactor --- src/misc/count-same-renotes.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/misc/count-same-renotes.ts (limited to 'src/misc') diff --git a/src/misc/count-same-renotes.ts b/src/misc/count-same-renotes.ts new file mode 100644 index 0000000000..0233bdf88e --- /dev/null +++ b/src/misc/count-same-renotes.ts @@ -0,0 +1,15 @@ +import { Notes } from '../models'; + +export async function countSameRenotes(userId: string, renoteId: string, excludeNoteId: string | undefined): Promise { + // 指定したユーザーの指定したノートのリノートがいくつあるか数える + 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(); +} -- cgit v1.2.3-freya