summaryrefslogtreecommitdiff
path: root/src/services/note/watch.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/note/watch.ts')
-rw-r--r--src/services/note/watch.ts31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/services/note/watch.ts b/src/services/note/watch.ts
index aad53610d8..d3c9553696 100644
--- a/src/services/note/watch.ts
+++ b/src/services/note/watch.ts
@@ -1,25 +1,20 @@
-import * as mongodb from 'mongodb';
-import Watching from '../../models/note-watching';
+import { User } from '../../models/entities/user';
+import { Note } from '../../models/entities/note';
+import { NoteWatchings } from '../../models';
+import { genId } from '../../misc/gen-id';
+import { NoteWatching } from '../../models/entities/note-watching';
-export default async (me: mongodb.ObjectID, note: object) => {
+export default async (me: User['id'], note: Note) => {
// 自分の投稿はwatchできない
- if (me.equals((note as any).userId)) {
+ if (me === note.userId) {
return;
}
- // if watching now
- const exist = await Watching.findOne({
- noteId: (note as any)._id,
- userId: me
- });
-
- if (exist !== null) {
- return;
- }
-
- await Watching.insert({
+ await NoteWatchings.save({
+ id: genId(),
createdAt: new Date(),
- noteId: (note as any)._id,
- userId: me
- });
+ noteId: note.id,
+ userId: me,
+ noteUserId: note.userId
+ } as NoteWatching);
};