diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2019-02-05 01:24:44 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2019-02-05 01:24:44 +0900 |
| commit | 1d814ba0e124e97ec72361254f42a76f6a0449ae (patch) | |
| tree | ae18ea8043b73b6cd3dd0d5804d48b5b02869550 /src/server/api/endpoints/notes/state.ts | |
| parent | [API] お気に入り状態は投稿情報に含めないように統一 (diff) | |
| download | sharkey-1d814ba0e124e97ec72361254f42a76f6a0449ae.tar.gz sharkey-1d814ba0e124e97ec72361254f42a76f6a0449ae.tar.bz2 sharkey-1d814ba0e124e97ec72361254f42a76f6a0449ae.zip | |
個別に投稿のウォッチ/ウォッチ解除をできるように
Resolve #161
Diffstat (limited to 'src/server/api/endpoints/notes/state.ts')
| -rw-r--r-- | src/server/api/endpoints/notes/state.ts | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/server/api/endpoints/notes/state.ts b/src/server/api/endpoints/notes/state.ts index d8adc48c94..e9db12ead7 100644 --- a/src/server/api/endpoints/notes/state.ts +++ b/src/server/api/endpoints/notes/state.ts @@ -1,6 +1,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import define from '../../define'; import Favorite from '../../../../models/favorite'; +import NoteWatching from '../../../../models/note-watching'; export const meta = { stability: 'stable', @@ -25,14 +26,23 @@ export const meta = { }; export default define(meta, (ps, user) => new Promise(async (res, rej) => { - const favorite = await Favorite.count({ - userId: user._id, - noteId: ps.noteId - }, { - limit: 1 - }); + const [favorite, watching] = await Promise.all([ + Favorite.count({ + userId: user._id, + noteId: ps.noteId + }, { + limit: 1 + }), + NoteWatching.count({ + userId: user._id, + noteId: ps.noteId + }, { + limit: 1 + }) + ]); res({ - isFavorited: favorite !== 0 + isFavorited: favorite !== 0, + isWatching: watching !== 0 }); })); |