Skip to content

Commit 8737341

Browse files
dotansimhadarkbasic
authored andcommitted
Step 13.27: Add after hook for user modification
1 parent b0c2fd9 commit 8737341

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

api/server/collections/users.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import { MongoObservable } from 'meteor-rxjs';
22
import { Meteor } from 'meteor/meteor';
33
import { User } from '../models';
4+
import { Pictures } from './pictures';
45

56
export const Users = MongoObservable.fromExisting<User>(Meteor.users);
7+
8+
// Dispose unused profile pictures
9+
Meteor.users.after.update(function (userId, doc, fieldNames, modifier, options) {
10+
if (!doc.profile) return;
11+
if (!this.previous.profile) return;
12+
if (doc.profile.pictureId == this.previous.profile.pictureId) return;
13+
14+
Pictures.collection.remove({ _id: this.previous.profile.pictureId });
15+
}, { fetchPrevious: true });

0 commit comments

Comments
 (0)