Permalink
Browse files

Step 10.10: Add party publication

  • Loading branch information...
1 parent e839918 commit 537ebd91ce26f5706f93d3e1ceeedf25a6bf43d2 @kamilkisiela kamilkisiela committed with DAB0mB Sep 22, 2016
Showing with 23 additions and 3 deletions.
  1. +23 −3 server/imports/publications/parties.ts
@@ -2,7 +2,16 @@ import { Meteor } from 'meteor/meteor';
import { Parties } from '../../../both/collections/parties.collection';
Meteor.publish('parties', function() {
- const selector = {
+ return Parties.find(buildQuery.call(this));
+});
+
+Meteor.publish('party', function(partyId: string) {
+ return Parties.find(buildQuery.call(this, partyId));
+});
+
+
+function buildQuery(partyId?: string): Object {
+ const isAvailable = {
$or: [{
// party is public
public: true
@@ -20,5 +29,16 @@ Meteor.publish('parties', function() {
}]
};
- return Parties.find(selector);
-});
+ if (partyId) {
+ return {
+ // only single party
+ $and: [{
+ _id: partyId
+ },
+ isAvailable
+ ]
+ };
+ }
+
+ return isAvailable;
+}

0 comments on commit 537ebd9

Please sign in to comment.