mizzkey/src/queue/processors/db/delete-post-dependents.ts

23 lines
799 B
TypeScript
Raw Normal View History

2018-04-04 22:45:55 +09:00
import Favorite from '../../../models/favorite';
import Notification from '../../../models/notification';
import PollVote from '../../../models/poll-vote';
import PostReaction from '../../../models/post-reaction';
import PostWatching from '../../../models/post-watching';
import Post from '../../../models/post';
2018-04-03 17:50:52 +09:00
export default ({ data }, done) => Promise.all([
2018-04-03 17:50:52 +09:00
Favorite.remove({ postId: data._id }),
Notification.remove({ postId: data._id }),
PollVote.remove({ postId: data._id }),
PostReaction.remove({ postId: data._id }),
PostWatching.remove({ postId: data._id }),
Post.find({ repostId: data._id }).then(reposts => Promise.all([
Notification.remove({
postId: {
$in: reposts.map(({ _id }) => _id)
}
}),
Post.remove({ repostId: data._id })
]))
]).then(() => done(), done);