-
Notifications
You must be signed in to change notification settings - Fork 2
/
model.js
31 lines (26 loc) · 868 Bytes
/
model.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Players = new Meteor.Collection('players');
// {name: 'David', game: 'foosball', wins: 4, losses: 3, last_game: 12345...}
Games = new Meteor.Collection('games');
// {name: 'Foosball', href: 'foosball'}
Results = new Meteor.Collection('results');
// {winner: 'David', loser: 'Bob', game: foosball, timestamp: 12345, winner_change: 10, loser_change: 9}
if (Meteor.isServer) {
Meteor.publish('games', function(game) {
if (game && game.length > 0) {
return Games.find({href: game});
} else {
return Games.find({});
}
});
Meteor.publish('players', function(game) {
return Players.find({game: game});
});
Meteor.publish('results', function(game, player) {
if (player) {
return Results.find(
{game: game,
$or: [{winner: player}, {loser: player}]});
}
return Results.find({game: game});
});
}