mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-13 11:33:09 +02:00
22 lines
416 B
TypeScript
22 lines
416 B
TypeScript
|
import * as mongodb from 'mongodb';
|
||
|
import Watching from '../models/post-watching';
|
||
|
|
||
|
export default async (me: mongodb.ObjectID, post: mongodb.ObjectID) => {
|
||
|
// if watching now
|
||
|
const exist = await Watching.findOne({
|
||
|
post_id: post,
|
||
|
user_id: me,
|
||
|
deleted_at: { $exists: false }
|
||
|
});
|
||
|
|
||
|
if (exist !== null) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
await Watching.insert({
|
||
|
created_at: new Date(),
|
||
|
post_id: post,
|
||
|
user_id: me
|
||
|
});
|
||
|
};
|