diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-06-07 00:44:26 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-06-07 00:44:26 +0900 |
| commit | 079f2098e3047c299b2e6d113efee26f1edad361 (patch) | |
| tree | d27d729e7d249c3adaa5853fa845fc71a871d9a0 /src/api/common | |
| parent | Merge pull request #536 from syuilo/greenkeeper/ts-node-3.0.5 (diff) | |
| download | sharkey-079f2098e3047c299b2e6d113efee26f1edad361.tar.gz sharkey-079f2098e3047c299b2e6d113efee26f1edad361.tar.bz2 sharkey-079f2098e3047c299b2e6d113efee26f1edad361.zip | |
WIP #161
Diffstat (limited to 'src/api/common')
| -rw-r--r-- | src/api/common/watch-post.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/api/common/watch-post.ts b/src/api/common/watch-post.ts new file mode 100644 index 0000000000..9f5e7a9130 --- /dev/null +++ b/src/api/common/watch-post.ts @@ -0,0 +1,21 @@ +import * as mongodb from 'mongodb'; +import Watching from '../models/post-watching'; + +export default async (me: mongodb.ObjectID, post: mongodb.ObjectID) => { + // if watching now + const exist = await Watching.findOne({ + post_id: post, + user_id: me, + deleted_at: { $exists: false } + }); + + if (exist !== null) { + return; + } + + await Watching.insert({ + created_at: new Date(), + post_id: post, + user_id: me + }); +}; |