Skip to content

Commit

Permalink
Step 10.10: Add party publication
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored and DAB0mB committed Dec 14, 2016
1 parent e839918 commit 537ebd9
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions server/imports/publications/parties.ts
Expand Up @@ -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
Expand All @@ -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.