From 719fac6480f8bd39498f2e92c83cac0fa26fb282 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 13 Oct 2018 00:54:30 +0900 Subject: お気に入りを解除できるように MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/note.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/models/note.ts') diff --git a/src/models/note.ts b/src/models/note.ts index a47fd098c7..e6bdbe0b8b 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -358,8 +358,8 @@ export const pack = async ( })(_note.poll); } - // Fetch my reaction if (meId) { + // Fetch my reaction _note.myReaction = (async () => { const reaction = await Reaction .findOne({ @@ -374,6 +374,19 @@ export const pack = async ( return null; })(); + + // isFavorited + _note.isFavorited = (async () => { + const favorite = await Favorite + .count({ + userId: meId, + noteId: id + }, { + limit: 1 + }); + + return favorite === 1; + })(); } } -- cgit v1.2.3-freya