2016-11-14 17:17:44 +09:00
|
|
|
import Posts from '../collection.js'
|
|
|
|
import Users from 'meteor/nova:users';
|
2016-12-13 11:40:24 +09:00
|
|
|
import { addCallback } from 'meteor/nova:core';
|
2016-11-14 17:17:44 +09:00
|
|
|
|
|
|
|
// ------------------------------------- posts.remove.sync -------------------------------- //
|
|
|
|
|
|
|
|
function PostsRemoveOperations (post) {
|
2017-01-18 10:18:33 +09:00
|
|
|
Users.update({_id: post.userId}, {$inc: {"postCount": -1}});
|
2016-11-14 17:17:44 +09:00
|
|
|
}
|
2016-12-13 11:40:24 +09:00
|
|
|
addCallback("posts.remove.sync", PostsRemoveOperations);
|
2016-11-14 17:17:44 +09:00
|
|
|
|
|
|
|
// ------------------------------------- posts.approve.async -------------------------------- //
|
|
|
|
|
2016-11-30 16:54:58 +09:00
|
|
|
/**
|
|
|
|
* @summary set postedAt when a post is approved
|
|
|
|
*/
|
|
|
|
function PostsSetPostedAt (modifier, post) {
|
|
|
|
modifier.$set.postedAt = new Date();
|
|
|
|
return modifier;
|
|
|
|
}
|
2016-12-13 11:40:24 +09:00
|
|
|
addCallback("posts.approve.sync", PostsSetPostedAt);
|
2016-11-30 16:54:58 +09:00
|
|
|
|
2016-11-14 17:17:44 +09:00
|
|
|
|
|
|
|
// ------------------------------------- users.remove.async -------------------------------- //
|
|
|
|
|
|
|
|
function UsersRemoveDeletePosts (user, options) {
|
|
|
|
if (options.deletePosts) {
|
2017-02-02 15:15:51 +01:00
|
|
|
Posts.remove({userId: user._id});
|
2016-11-14 17:17:44 +09:00
|
|
|
} else {
|
|
|
|
// not sure if anything should be done in that scenario yet
|
|
|
|
// Posts.update({userId: userId}, {$set: {author: "\[deleted\]"}}, {multi: true});
|
|
|
|
}
|
|
|
|
}
|
2017-02-02 15:15:51 +01:00
|
|
|
addCallback("users.remove.async", UsersRemoveDeletePosts);
|