mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-14 09:23:08 +02:00
25 lines
490 B
TypeScript
25 lines
490 B
TypeScript
import * as mongodb from 'mongodb';
|
|
import Watching from '../../models/note-watching';
|
|
|
|
export default async (me: mongodb.ObjectID, note: object) => {
|
|
// 自分の投稿はwatchできない
|
|
if (me.equals((note as any).userId)) {
|
|
return;
|
|
}
|
|
|
|
// if watching now
|
|
const exist = await Watching.findOne({
|
|
noteId: (note as any)._id,
|
|
userId: me
|
|
});
|
|
|
|
if (exist !== null) {
|
|
return;
|
|
}
|
|
|
|
await Watching.insert({
|
|
createdAt: new Date(),
|
|
noteId: (note as any)._id,
|
|
userId: me
|
|
});
|
|
};
|