@dhyasama/totem-models 9.31.0 → 9.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -50,6 +50,8 @@ var bootstrap = function(mongoose, config) {
50
50
  require('./lib/CalendarEvent.js')(mongoose, config);
51
51
  require('./lib/CapTable.js')(mongoose, config);
52
52
  require('./lib/Document.js')(mongoose, config);
53
+ require('./lib/Event.js')(mongoose, config);
54
+ require('./lib/EventAttendee.js')(mongoose, config);
53
55
  require('./lib/Financials.js')(mongoose, config);
54
56
  require('./lib/Interaction.js')(mongoose, config);
55
57
  require('./lib/Investment.js')(mongoose, config);
package/lib/Event.js ADDED
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+
3
+ module.exports = function(mongoose, config) {
4
+
5
+ const _ = require('underscore');
6
+ const Schema = mongoose.Schema;
7
+
8
+ const Event = new Schema({
9
+
10
+ // The customer this event belongs to
11
+ customer: {
12
+ type: Schema.ObjectId,
13
+ ref: 'Organization',
14
+ required: true,
15
+ index: true
16
+ },
17
+
18
+ // The provider the event is hosted on
19
+ provider: {
20
+ type: String,
21
+ required: true,
22
+ enum: [
23
+ 'Splash',
24
+ ],
25
+ default: 'Splash'
26
+ },
27
+
28
+ // Event information
29
+ EventId: { type: String, required: true },
30
+ EventTitle: { type: String, required: true },
31
+ EventStartDate: { type: Date, required: true },
32
+ EventEndDate: { type: Date, required: false },
33
+ EventTimezone: { type: String, required: true, default: 'America/New_York' },
34
+ EventUrl: { type: String, required: false }
35
+
36
+ });
37
+
38
+ Event.virtual('Attendees', {
39
+ ref: 'EventAttendee',
40
+ localField: '_id',
41
+ foreignField: 'Event',
42
+ justOne: true // for many-to-1 relationships
43
+ });
44
+
45
+ Event.statics.delete = function (id, options, cb) {
46
+
47
+ const self = this;
48
+
49
+ if (!cb) { throw new Error('cb is required'); }
50
+ if (!id) { return cb(new Error('id is required'), null); }
51
+ if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
52
+ if (!options) { return cb(new Error('options is required'), null); }
53
+
54
+ self.findByIdAndRemove(id, cb);
55
+
56
+ };
57
+
58
+ // Get a single event
59
+ // Double check customer id
60
+ // Optionally populate customer
61
+ Event.statics.getById = function (id, options, cb) {
62
+
63
+ const self = this;
64
+
65
+ if (!cb) { throw new Error('cb is required'); }
66
+ if (!id) { return cb(new Error('id is required'), null); }
67
+ if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
68
+ if (!options) { return cb(new Error('options is required'), null); }
69
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
70
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
71
+
72
+ let query = self.findOne({
73
+ '_id': id,
74
+ 'customer': options.CUSTOMER_ID
75
+ });
76
+
77
+ if (options.populate) {
78
+ query.populate('Attendees');
79
+ query.populate('customer');
80
+ }
81
+
82
+ query.exec(cb);
83
+
84
+ };
85
+
86
+ // Get all events a customer has held
87
+ // Optionally populate customer
88
+ Event.statics.list = function(customerId, options, cb) {
89
+
90
+ const self = this;
91
+
92
+ if (!cb) throw new Error('callback is required');
93
+ if (!options) options = {};
94
+ if (!customerId) throw new Error('customerId is required');
95
+ if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
96
+
97
+ let query = self.find({ customer: customerId });
98
+
99
+ if (options.populate) {
100
+ query.populate('Attendees');
101
+ query.populate('customer');
102
+ }
103
+
104
+ query.exec(cb);
105
+
106
+ };
107
+
108
+ // Create or update an event
109
+ Event.statics.upsert = function(event, options, cb) {
110
+
111
+ if (!cb) throw new Error('cb is required');
112
+ if (!event) throw new Error('event is required');
113
+ if (!options) { return cb(new Error('options is required'), null); }
114
+
115
+ event.save(cb);
116
+
117
+ };
118
+
119
+ Event.set('usePushEach', true);
120
+ Event.set('autoIndex', false);
121
+ Event.set('toJSON', { virtuals: true });
122
+ Event.set('toObject', { virtuals: true });
123
+ Event.on('index', function(err) { console.log('error building event indexes: ' + err); });
124
+
125
+ mongoose.model('Event', Event);
126
+
127
+ };
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+
3
+ module.exports = function(mongoose, config) {
4
+
5
+ const Schema = mongoose.Schema;
6
+
7
+ const EventAttendee = new Schema({
8
+
9
+ Event: {
10
+ type: Schema.ObjectId,
11
+ ref: 'Event',
12
+ required: true,
13
+ index: true
14
+ },
15
+
16
+ Email: { type: String, required: true, index: true },
17
+
18
+ ProviderEventId: { type: String, required: true },
19
+
20
+ ProviderContactId: { type: String, required: true },
21
+
22
+ ProviderGuestListStatus: {
23
+ type: String,
24
+ required: true,
25
+ enum: [
26
+ 'invited',
27
+ 'rsvp_yes',
28
+ 'rsvp_no',
29
+ 'checkin_yes'
30
+ ]
31
+ }
32
+
33
+ });
34
+
35
+ // Delete an attendee of an event
36
+ EventAttendee.statics.delete = function (eventId, email, options, cb) {
37
+
38
+ const self = this;
39
+
40
+ if (!cb) { throw new Error('cb is required'); }
41
+ if (!eventId) { return cb(new Error('eventId is required'), null); }
42
+ if (!mongoose.Types.ObjectId.isValid(eventId)) { return cb(new Error('eventId is not a valid ObjectId'), null); }
43
+ if (!email) { return cb(new Error('email is required'), null); }
44
+ if (!options) { return cb(new Error('options is required'), null); }
45
+
46
+ self.findOneAndRemove({ Event: eventId, Email: email }, cb);
47
+
48
+ };
49
+
50
+ // DO NOT IMPLEMENT
51
+ // Use Event, with populate true, to get the attendees of an event
52
+ // Having it here would be redundant
53
+ // Get all the attendees for an event
54
+ // EventAttendee.statics.listAllAttendeesOfEvent = function (eventId, options, cb) {
55
+ //
56
+ //
57
+ //
58
+ // };
59
+
60
+ // Get all the events an attendee attended
61
+ // Email can be a single email or an array of emails
62
+ // Optionally populate the event
63
+ EventAttendee.statics.listAllEventsForAttendee = function (email, options, cb) {
64
+
65
+ const self = this;
66
+
67
+ if (!cb) { throw new Error('cb is required'); }
68
+ if (!email) { return cb(new Error('email is required'), null); }
69
+ if (!options) { return cb(new Error('options is required'), null); }
70
+
71
+
72
+ // todo - filter customer
73
+
74
+
75
+
76
+ let params;
77
+
78
+ if (Array.isArray(email)) {
79
+ params = { Email: { $in : email }};
80
+ }
81
+ else {
82
+ params = { Email: email };
83
+ }
84
+
85
+ let query = self.find(params);
86
+
87
+ if (options.populate) {
88
+ query.populate('Event');
89
+ }
90
+
91
+ query.exec(cb);
92
+
93
+ };
94
+
95
+ // Update status for an attendee of an event
96
+ EventAttendee.statics.setGuestListStatus = function(eventId, email, status, options, cb) {
97
+
98
+ const self = this;
99
+
100
+ if (!cb) throw new Error('cb is required');
101
+ if (!eventId) throw new Error('eventAttendee is required');
102
+ if (!mongoose.Types.ObjectId.isValid(eventId)) { return cb(new Error('eventId is not a valid ObjectId'), null); }
103
+ if (!email) throw new Error('eventAttendee is required');
104
+ if (!status) throw new Error('eventAttendee is required');
105
+ if (!options) { return cb(new Error('options is required'), null); }
106
+
107
+ const conditions = {
108
+ Event: eventId,
109
+ Email: email
110
+ };
111
+
112
+ const update = {
113
+ $set: {
114
+ 'ProviderGuestListStatus' : status
115
+ }
116
+ };
117
+
118
+ self.findOneAndUpdate(conditions, update, { upsert: false, new: true }, cb);
119
+
120
+ };
121
+
122
+ // Update an attendee of an event
123
+ EventAttendee.statics.upsert = function(eventAttendee, options, cb) {
124
+
125
+ if (!cb) throw new Error('cb is required');
126
+ if (!eventAttendee) throw new Error('eventAttendee is required');
127
+ if (!options) { return cb(new Error('options is required'), null); }
128
+
129
+ eventAttendee.save(cb);
130
+
131
+ };
132
+
133
+ EventAttendee.set('usePushEach', true);
134
+ EventAttendee.set('autoIndex', false);
135
+
136
+ EventAttendee.on('index', function(err) { console.log('error building event attendee indexes: ' + err); });
137
+
138
+ mongoose.model('EventAttendee', EventAttendee);
139
+
140
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "9.31.0",
3
+ "version": "9.32.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
package/test/Event.js ADDED
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+
3
+ var
4
+
5
+ should = require("should"),
6
+ config = require('./config')['test'],
7
+ mongoose = require('mongoose'),
8
+ clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
9
+ Event = mongoose.model('Event'),
10
+ EventAttendee = mongoose.model('EventAttendee');
11
+
12
+ const customerOneId = new mongoose.Types.ObjectId();
13
+ const customerTwoId = new mongoose.Types.ObjectId();
14
+
15
+ let customerOneEvent;
16
+ let customerTwoEvent;
17
+
18
+ describe('Event', function() {
19
+
20
+ before(function(done) {
21
+
22
+ console.log('DB url:', config.db.uri);
23
+
24
+ if (config.db.uri.indexOf('test') === -1) {
25
+ console.log('Not test db, shutting down');
26
+ process.exit();
27
+ }
28
+ else {
29
+ if (mongoose.connection.db) { return done(); }
30
+ else { mongoose.connect(config.db.uri, done); }
31
+ }
32
+
33
+ });
34
+
35
+ before(function(done) {
36
+ clearDB(done);
37
+ });
38
+
39
+ it('adds an event for a customer', function(done) {
40
+
41
+ let e = new Event();
42
+ e.customer = customerOneId;
43
+ e.EventId = 'my-funny-id';
44
+ e.EventTitle = 'My Funny Event';
45
+ e.EventStartDate = new Date();
46
+
47
+ Event.upsert(e, {}, function(err, result) {
48
+
49
+ should.not.exist(err);
50
+ should.exist(result);
51
+
52
+ customerOneEvent = result;
53
+
54
+ return done();
55
+
56
+ });
57
+
58
+ });
59
+
60
+ it('adds an event for a different customer', function(done) {
61
+
62
+ let e = new Event();
63
+ e.customer = customerTwoId;
64
+ e.EventId = 'my-hilarious-id';
65
+ e.EventTitle = 'My Hilarious Event';
66
+ e.EventStartDate = new Date();
67
+
68
+ Event.upsert(e, {}, function(err, result) {
69
+
70
+ should.not.exist(err);
71
+ should.exist(result);
72
+
73
+ customerTwoEvent = result;
74
+
75
+ return done();
76
+
77
+ });
78
+
79
+ });
80
+
81
+ it('gets an event', function(done) {
82
+
83
+ Event.getById(customerOneEvent._id, { CUSTOMER_ID: customerOneId }, function(err, result) {
84
+
85
+ should.not.exist(err);
86
+ should.exist(result);
87
+ result._id.toString().should.equal(customerOneEvent._id.toString());
88
+
89
+ return done();
90
+
91
+ });
92
+
93
+ });
94
+
95
+ it('gets the attendees of an event', function(done) {
96
+
97
+ let attendee = new EventAttendee();
98
+ attendee.Event = customerOneEvent;
99
+ attendee.Email = 'jason@totemvc.com';
100
+ attendee.ProviderEventId = 'my-funny-id';
101
+ attendee.ProviderContactId = 'abc123';
102
+ attendee.ProviderGuestListStatus = 'invited';
103
+
104
+ EventAttendee.upsert(attendee, {}, function(err, result) {
105
+
106
+ should.not.exist(err);
107
+ should.exist(result);
108
+
109
+ Event.getById(customerOneEvent._id, { CUSTOMER_ID: customerOneId, populate: true }, function(err, result) {
110
+
111
+ should.not.exist(err);
112
+ should.exist(result);
113
+ should.exist(result.Attendees);
114
+
115
+ return done();
116
+
117
+ });
118
+
119
+ });
120
+
121
+ });
122
+
123
+ it('updates an event', function(done) {
124
+
125
+ const newTitle = 'My Event Funnier Event';
126
+
127
+ customerOneEvent.EventTitle = newTitle;
128
+
129
+ Event.upsert(customerOneEvent, {}, function(err, result) {
130
+
131
+ should.not.exist(err);
132
+ should.exist(result);
133
+ should.exist(result.EventTitle);
134
+ result.EventTitle.should.equal(newTitle);
135
+
136
+ return done();
137
+
138
+ });
139
+
140
+ });
141
+
142
+ it('cannot get an event belonging to another customer', function(done) {
143
+
144
+ Event.getById(customerOneEvent._id, { CUSTOMER_ID: customerTwoId }, function(err, result) {
145
+
146
+ should.not.exist(err);
147
+ should.not.exist(result);
148
+
149
+ return done();
150
+
151
+ });
152
+
153
+ });
154
+
155
+ it('removes an event', function(done) {
156
+
157
+ Event.delete(customerTwoEvent._id, {}, function(err, result) {
158
+
159
+ should.not.exist(err);
160
+
161
+ return done();
162
+
163
+ });
164
+
165
+ });
166
+
167
+ it('gets all events for a customer', function(done) {
168
+
169
+ Event.list(customerOneId, {}, function(err, result) {
170
+
171
+ should.not.exist(err);
172
+ should.exist(result);
173
+ result.length.should.equal(1);
174
+
175
+ return done();
176
+
177
+ });
178
+
179
+ });
180
+
181
+ it('gets all events for a customer that does not have events', function(done) {
182
+
183
+ Event.list(customerTwoId, {}, function(err, result) {
184
+
185
+ should.not.exist(err);
186
+ should.exist(result);
187
+ result.length.should.equal(0);
188
+
189
+ return done();
190
+
191
+ });
192
+
193
+ });
194
+
195
+ });
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+
3
+ var
4
+
5
+ should = require("should"),
6
+ config = require('./config')['test'],
7
+ mongoose = require('mongoose'),
8
+ clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
9
+ Event = mongoose.model('Event'),
10
+ EventAttendee = mongoose.model('EventAttendee');
11
+
12
+ const customerOneId = new mongoose.Types.ObjectId();
13
+
14
+ let customerOneEvent;
15
+ let customerTwoEvent;
16
+ let attendeeOne;
17
+
18
+ describe.only('EventAttendee', function() {
19
+
20
+ before(function(done) {
21
+
22
+ console.log('DB url:', config.db.uri);
23
+
24
+ if (config.db.uri.indexOf('test') === -1) {
25
+ console.log('Not test db, shutting down');
26
+ process.exit();
27
+ }
28
+ else {
29
+ if (mongoose.connection.db) { return done(); }
30
+ else { mongoose.connect(config.db.uri, done); }
31
+ }
32
+
33
+ });
34
+
35
+ before(function(done) {
36
+ clearDB(done);
37
+ });
38
+
39
+ before(function(done) {
40
+
41
+ let e = new Event();
42
+ e.customer = customerOneId;
43
+ e.EventId = 'my-funny-id';
44
+ e.EventTitle = 'My Funny Event';
45
+ e.EventStartDate = new Date();
46
+
47
+ Event.upsert(e, {}, function(err, result) {
48
+
49
+ should.not.exist(err);
50
+ should.exist(result);
51
+
52
+ customerOneEvent = result;
53
+
54
+ let e = new Event();
55
+ e.customer = customerOneId;
56
+ e.EventId = 'my-boring-id';
57
+ e.EventTitle = 'My Boring Event';
58
+ e.EventStartDate = new Date();
59
+
60
+ Event.upsert(e, {}, function(err, result) {
61
+
62
+ should.not.exist(err);
63
+ should.exist(result);
64
+
65
+ customerTwoEvent = result;
66
+
67
+ return done();
68
+
69
+ });
70
+
71
+ });
72
+
73
+ });
74
+
75
+ it('adds an attendee to an event', function(done) {
76
+
77
+ let attendee = new EventAttendee();
78
+ attendee.Event = customerOneEvent;
79
+ attendee.Email = 'jason@totemvc.com';
80
+ attendee.ProviderEventId = 'my-funny-id';
81
+ attendee.ProviderContactId = 'abc123';
82
+ attendee.ProviderGuestListStatus = 'invited';
83
+
84
+ EventAttendee.upsert(attendee, {}, function(err, result) {
85
+
86
+ should.not.exist(err);
87
+ should.exist(result);
88
+
89
+ attendeeOne = result;
90
+
91
+ return done();
92
+
93
+ });
94
+
95
+ });
96
+
97
+ it('adds a second attendee to an event', function(done) {
98
+
99
+ let attendee = new EventAttendee();
100
+ attendee.Event = customerOneEvent;
101
+ attendee.Email = 'dhyasama@gmail.com';
102
+ attendee.ProviderEventId = 'my-funny-id';
103
+ attendee.ProviderContactId = 'def456';
104
+ attendee.ProviderGuestListStatus = 'rsvp_yes';
105
+
106
+ EventAttendee.upsert(attendee, {}, function(err, result) {
107
+
108
+ should.not.exist(err);
109
+ should.exist(result);
110
+
111
+ return done();
112
+
113
+ });
114
+
115
+ });
116
+
117
+ it('gets all the events for an attendee with a single email', function(done) {
118
+
119
+ EventAttendee.listAllEventsForAttendee('dhyasama@gmail.com', { populate: true }, function(err, result) {
120
+
121
+ should.not.exist(err);
122
+ should.exist(result);
123
+ result.length.should.equal(1);
124
+ should.exist(result[0].Event);
125
+ should.exist(result[0].Event.EventTitle);
126
+ result[0].Event.EventTitle.should.equal('My Funny Event');
127
+
128
+ return done();
129
+
130
+ });
131
+
132
+ });
133
+
134
+ it('gets all the events for an attendee with two emails', function(done) {
135
+
136
+ EventAttendee.listAllEventsForAttendee(['dhyasama@gmail.com', 'dhyasama+test@gmail.com'], { populate: true }, function(err, result) {
137
+
138
+ should.not.exist(err);
139
+ should.exist(result);
140
+ result.length.should.equal(1);
141
+ should.exist(result[0].Event);
142
+ should.exist(result[0].Event.EventTitle);
143
+ result[0].Event.EventTitle.should.equal('My Funny Event');
144
+
145
+ return done();
146
+
147
+ });
148
+
149
+ });
150
+
151
+ it('updates an event attendee', function(done) {
152
+
153
+ attendeeOne.ProviderContactId = 'ghi789';
154
+
155
+ EventAttendee.upsert(attendeeOne, {}, function(err, result) {
156
+
157
+ should.not.exist(err);
158
+ should.exist(result);
159
+ should.exist(result.ProviderContactId);
160
+ result.ProviderContactId.should.equal('ghi789');
161
+
162
+ attendeeOne = result;
163
+
164
+ return done();
165
+
166
+ });
167
+
168
+ });
169
+
170
+ it('updates an event status', function(done) {
171
+
172
+ EventAttendee.setGuestListStatus(customerOneEvent._id, 'jason@totemvc.com', 'rsvp_yes', {}, function(err, result) {
173
+
174
+ should.not.exist(err);
175
+ should.exist(result);
176
+ should.exist(result.ProviderGuestListStatus);
177
+ result.ProviderGuestListStatus.should.equal('rsvp_yes');
178
+
179
+ attendeeOne = result;
180
+
181
+ return done();
182
+
183
+ });
184
+
185
+ });
186
+
187
+ });
package/test/Round.js CHANGED
@@ -18,9 +18,9 @@ var personid = new mongoose.Types.ObjectId();
18
18
  var fundid = new mongoose.Types.ObjectId();
19
19
  var organization, organization2, fund, person, investment, investment2;
20
20
 
21
- describe.only('Rounds', function() {
21
+ describe('Rounds', function() {
22
22
 
23
- config.db.uri = 'mongodb://jason:T576G150HPXLA5q4BJ2o2zj747B5030x@production-shard-00-00-gv0f3.mongodb.net:27017,production-shard-00-01-gv0f3.mongodb.net:27017,production-shard-00-02-gv0f3.mongodb.net:27017/production?replicaSet=Production-shard-0&ssl=true&authSource=admin'
23
+ //config.db.uri = 'mongodb://jason:T576G150HPXLA5q4BJ2o2zj747B5030x@production-shard-00-00-gv0f3.mongodb.net:27017,production-shard-00-01-gv0f3.mongodb.net:27017,production-shard-00-02-gv0f3.mongodb.net:27017/production?replicaSet=Production-shard-0&ssl=true&authSource=admin'
24
24
 
25
25
  before(function(done) {
26
26
  if (mongoose.connection.db) return done();