This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.coffee
69 lines (57 loc) · 1.58 KB
/
model.coffee
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Shared code - server and client
currentPerson = null
People = new Meteor.Collection("people")
People.default_data =
name : null
picks :
A1 : null
A2 : null
B1 : null
B2 : null
C1 : null
C2 : null
D1 : null
D2 : null
Q1 : null
Q2 : null
Q3 : null
Q4 : null
S1 : null
S2 : null
winner: null
tiebreaker : null
Meteor.methods(
add_person : (person) ->
# if already exists, do nothing
existent = People.findOne(name : person.name)
if existent? and existent.picks?
return new Meteor.Error(403, "Person already exists", "Sorry, but you only get one chance")
else
if existent?
id = People.update({name: existent.name}, person)
else
id = People.insert(person)
return id
get_person : (name) ->
result = People.findOne(name : name)
if result?
return result
else
return false
get_all_people : ->
People.find({}).fetch()
admin_update : (new_data) ->
People.update({name : "admin"}, new_data)
)
if Meteor.is_server
# Publish all the people
Meteor.publish 'people', () -> People.find({}).fetch()
Meteor.startup ->
if People.findOne({name:"admin"}) == undefined
admin = People.default_data
admin.name = "admin"
People.insert(admin)
if Meteor.is_client
Meteor.startup ->
# Subscribe to dataset
Meteor.subscribe('people')