WIP #161
This commit is contained in:
parent
eea09bc376
commit
079f2098e3
4 changed files with 80 additions and 0 deletions
21
src/api/common/watch-post.ts
Normal file
21
src/api/common/watch-post.ts
Normal file
|
|
@ -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
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue