mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-12-30 06:28:04 +09:00
27 lines
523 B
TypeScript
27 lines
523 B
TypeScript
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).userId)) {
|
|
return;
|
|
}
|
|
|
|
// if watching now
|
|
const exist = await Watching.findOne({
|
|
postId: (post as any)._id,
|
|
userId: me,
|
|
deletedAt: { $exists: false }
|
|
});
|
|
|
|
if (exist !== null) {
|
|
return;
|
|
}
|
|
|
|
await Watching.insert({
|
|
createdAt: new Date(),
|
|
postId: (post as any)._id,
|
|
userId: me
|
|
});
|
|
};
|