Skip to content

Instantly share code, notes, and snippets.

@yogiben
Created April 7, 2016 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yogiben/3260ab8c19e2a56ccb78b1067341ae73 to your computer and use it in GitHub Desktop.
Save yogiben/3260ab8c19e2a56ccb78b1067341ae73 to your computer and use it in GitHub Desktop.
/*
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