Permalink
Browse files

Step 13.27: Add after hook for user modification

  • Loading branch information...
dotansimha authored and darkbasic committed Jan 24, 2017
1 parent b0c2fd9 commit 8737341141f07d9c1d58920475d084107715bfdd
Showing with 10 additions and 0 deletions.
  1. +10 −0 api/server/collections/users.ts
@@ -1,5 +1,15 @@
import { MongoObservable } from 'meteor-rxjs';
import { Meteor } from 'meteor/meteor';
import { User } from '../models';
import { Pictures } from './pictures';
export const Users = MongoObservable.fromExisting<User>(Meteor.users);
// Dispose unused profile pictures
Meteor.users.after.update(function (userId, doc, fieldNames, modifier, options) {
if (!doc.profile) return;
if (!this.previous.profile) return;
if (doc.profile.pictureId == this.previous.profile.pictureId) return;
Pictures.collection.remove({ _id: this.previous.profile.pictureId });
}, { fetchPrevious: true });

0 comments on commit 8737341

Please sign in to comment.