Skip to content

Commit

Permalink
Step 16.5: Create the saveFcmToken Meteor method
Browse files Browse the repository at this point in the history
  • Loading branch information
darkbasic committed Oct 16, 2017
1 parent 8927c7d commit e0e7214
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/server/methods.ts
Expand Up @@ -2,6 +2,7 @@ import { Chats } from './collections/chats';
import { Messages } from './collections/messages';
import { MessageType, Profile } from './models';
import { check, Match } from 'meteor/check';
import { Users } from "./collections/users";

const nonEmptyString = Match.Where((str) => {
check(str, String);
Expand Down Expand Up @@ -94,5 +95,12 @@ Meteor.methods({
},
countMessages(): number {
return Messages.collection.find().count();
},
saveFcmToken(token: string): void {
if (!this.userId) throw new Meteor.Error('unauthorized', 'User must be logged-in to call this method');

check(token, nonEmptyString);

Users.collection.update({_id: this.userId}, {$set: {"fcmToken": token}});
}
});

0 comments on commit e0e7214

Please sign in to comment.