-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodel.js
More file actions
166 lines (142 loc) · 4.06 KB
/
model.js
File metadata and controls
166 lines (142 loc) · 4.06 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
Friends = new Meteor.Collection("friends");
Friends.allow({
insert: function(userId, friendName) {
return true;
},
update: function(userId, friendName) {
return true;
}, //update the friend list
remove: function(userId, friendName) {
return false;
}
});
CurrentEvents = new Meteor.Collection("current_events");
PastEvents = new Meteor.Collection("past_events");
Sign = new Meteor.Collection("Sign");
CurrentEvents.allow({
insert: function(userId, myEvent) {
return false;
},
update: function(userId, myEvent, fields, modifier) {
if (userId !== myEvent.owner) {
return false;
}
var allowed = ["name", "description", "x", "y"];
if (_.difference(fields, allowed).length)
return false;
},
remove: function(userId, myEvent) {
return true;
}
});
Sign.allow ({
insert: function() {
return true;
}
});
PastEvents.allow({
insert: function(userId, hisEvent) {
return true;
},
remove: function(userId, hisEvent) {
return true;
}
});
attending = function(myEvent) {
return myEvent.attendees.length;
};
createEvent = function(options) {
var id = Random.id();
Meteor.call('createEvent', _.extend({_id: id}, options));
return id;
};
createPastEvent = function(options) {
Meteor.call('createPastEvent', options);
}
Meteor.methods({
createEvent: function(options) {
check(options, {
name: String,
description: String,
_id: String,
x: Number,
y: Number
});
var id = options._id || Random.id();
console.log("this.userId: " + this.userId);
var uName = displayName(Meteor.users.findOne(this.userId));
var uFID = Meteor.user().services.facebook.id;
var uEmail = Meteor.user().services.facebook.email;
console.log("Username of creator: " + uName);
CurrentEvents.insert({
_id: id,
owner: this.userId,
x: options.x,
y: options.y,
name: options.name,
description: options.description,
attendees: [{name: uName, email: uEmail, fbook_id: uFID}]
});
return id;
},
createPastEvent: function(options) {
},
sign_: function(eventId, signing_in) {
check(eventId, String);
if (! this.userId)
throw new Meteor.Error(403, "You must be logged in to sign " +
(signing_in ? "in" : "out") + "!");
var myEvent = CurrentEvents.findOne(eventId);
if (! myEvent)
throw new Meteor.Error(404, "There is no such event!");
var attendIndex = _.indexOf(this.userId);
var uName = displayName(Meteor.users.findOne(this.userId));
var uEmail = null;
var uFID = null;
if(Meteor.user().services.facebook) {
uEmail = Meteor.user().services.facebook.email;
uFID = Meteor.user().services.facebook.id;
} else {
uEmail = user.emails[o].address;
console.log("Email login: " + uEmail);
}
var updateTable = {name: uName, email: uEmail, fbook_id: uFID};
check(updateTable, {
name: String,
email: String,
fbook_id: String
});
check(this.userId, String);
if (attendIndex === -1) {
if (signing_in) {
CurrentEvents.update(eventId,
{$push: {attendees: updateTable}});
} else {
CurrentEvents.update(eventId,
{$pull: {attendees: updateTable}});
var userPastEvents = PastEvents.findOne({user: this.userId});
if (userPastEvents) {
console.log("User has past event entry");
PastEvents.update({user: this.userId}, {$addToSet: {events: eventId}});
} else {
PastEvents.insert({user: this.userId, events: [eventId]});
console.log("User did not have past event entry. Created new");
}
}
}
},
invite: function(partyId, userId) {
}
});
displayName = function(user) {
if (user.profile && user.profile.name)
return user.profile.name;
return user.emails[0].address;
};
contactEmail = function(user) {
if (user.emails && user.emails.length)
return user.emails[0].address;
if (user.services && user.services.facebook && user.services.facebook.email)
return user.services.facebook.email;
return null;
}