Created
April 7, 2016 16:50
-
-
Save yogiben/3260ab8c19e2a56ccb78b1067341ae73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Roles | |
*/ | |
// Client | |
Meteor.call('adminTask'); | |
// Server | |
Meteor.methods({ | |
adminTask() { | |
// Check if user in roles | |
const roles = Meteor.users.findOne(this.userId).roles | |
if (roles.indexOf === -1) { | |
throw new Meteor.Error(403, 'Not an admin'); | |
}; | |
... | |
} | |
}) | |
/* | |
Relational data in Meteor | |
*/ | |
// 1. Use publish composite | |
See examples: https://github.com/englue/meteor-publish-composite | |
// 2. Write a publish function that returns an array of cursors | |
Meteor.publish('books', () => { | |
const bookCursor = Books.find(); | |
const authorIds = Books.map((book) => book['authorId']); | |
const authorCursor = Authors.find({_id: {$in: authorIds}}); | |
return [bookCursor, authorCursor]; | |
}) | |
/* | |
Sorting with collection helpers | |
*/ | |
Books.find().fetch().getAuthors().sort(...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment