This commit is contained in:
syuilo
2017-06-07 01:20:07 +09:00
parent 079f2098e3
commit 6c4baf69ff
4 changed files with 63 additions and 6 deletions

View File

@@ -1,10 +1,15 @@
import * as mongodb from 'mongodb';
import Watching from '../models/post-watching';
export default async (me: mongodb.ObjectID, post: mongodb.ObjectID) => {
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,
post_id: (post as any)._id,
user_id: me,
deleted_at: { $exists: false }
});
@@ -15,7 +20,7 @@ export default async (me: mongodb.ObjectID, post: mongodb.ObjectID) => {
await Watching.insert({
created_at: new Date(),
post_id: post,
post_id: (post as any)._id,
user_id: me
});
};