diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-10-13 00:54:30 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-10-13 00:54:30 +0900 |
| commit | 719fac6480f8bd39498f2e92c83cac0fa26fb282 (patch) | |
| tree | e671e7b5e59777563f6799736a6d4a8fe45695e1 /src/models | |
| parent | 10.10.1 (diff) | |
| download | sharkey-719fac6480f8bd39498f2e92c83cac0fa26fb282.tar.gz sharkey-719fac6480f8bd39498f2e92c83cac0fa26fb282.tar.bz2 sharkey-719fac6480f8bd39498f2e92c83cac0fa26fb282.zip | |
お気に入りを解除できるように
Diffstat (limited to 'src/models')
| -rw-r--r-- | src/models/favorite.ts | 4 | ||||
| -rw-r--r-- | src/models/note.ts | 15 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/models/favorite.ts b/src/models/favorite.ts index 4824a6dbaa..9acaec5c59 100644 --- a/src/models/favorite.ts +++ b/src/models/favorite.ts @@ -75,7 +75,9 @@ export const pack = ( delete _favorite._id; // Populate note - _favorite.note = await packNote(_favorite.noteId, me); + _favorite.note = await packNote(_favorite.noteId, me, { + detail: true + }); // (データベースの不具合などで)投稿が見つからなかったら if (_favorite.note == null) { 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; + })(); } } |