Skip to content

Commit

Permalink
Step 12.24: Add after hook for user modification
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Feb 26, 2017
1 parent 3af2783 commit d68c948
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion imports/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);
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: doc.profile.pictureId });
}, { fetchPrevious: true });

0 comments on commit d68c948

Please sign in to comment.