Introduce processor
This commit is contained in:
parent
68ce6d5748
commit
90f8fe7e53
582 changed files with 246 additions and 188 deletions
26
src/server/api/common/watch-post.ts
Normal file
26
src/server/api/common/watch-post.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import * as mongodb from 'mongodb';
|
||||
import Watching from '../models/post-watching';
|
||||
|
||||
export default async (me: mongodb.ObjectID, post: object) => {
|
||||
// 自分の投稿はwatchできない
|
||||
if (me.equals((post as any).user_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if watching now
|
||||
const exist = await Watching.findOne({
|
||||
post_id: (post as any)._id,
|
||||
user_id: me,
|
||||
deleted_at: { $exists: false }
|
||||
});
|
||||
|
||||
if (exist !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
await Watching.insert({
|
||||
created_at: new Date(),
|
||||
post_id: (post as any)._id,
|
||||
user_id: me
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue