Vulcan/packages/nova-posts/lib/callbacks/callbacks_other.js
xavcz b67989fbc2 work on notifications
* Telescope.notifications.create -> import { createNotifications } from 'meteor/nova:notifications' ;
* leverage Meteor's weak dependencies on packages & move code related to emails / notifications from nova:posts et al. to nova:notifications
2017-02-16 10:04:00 +01:00

34 lines
1.1 KiB
JavaScript

import Posts from '../collection.js'
import Users from 'meteor/nova:users';
import { addCallback } from 'meteor/nova:core';
// ------------------------------------- posts.remove.sync -------------------------------- //
function PostsRemoveOperations (post) {
Users.update({_id: post.userId}, {$inc: {"postCount": -1}});
}
addCallback("posts.remove.sync", PostsRemoveOperations);
// ------------------------------------- posts.approve.async -------------------------------- //
/**
* @summary set postedAt when a post is approved
*/
function PostsSetPostedAt (modifier, post) {
modifier.$set.postedAt = new Date();
return modifier;
}
addCallback("posts.approve.sync", PostsSetPostedAt);
// ------------------------------------- users.remove.async -------------------------------- //
function UsersRemoveDeletePosts (user, options) {
if (options.deletePosts) {
Posts.remove({userId: user._id});
} else {
// not sure if anything should be done in that scenario yet
// Posts.update({userId: userId}, {$set: {author: "\[deleted\]"}}, {multi: true});
}
}
addCallback("users.remove.async", UsersRemoveDeletePosts);