@dhyasama/totem-models 1.29.2 → 1.30.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
@@ -45,15 +45,18 @@ var bootstrap = function(mongoose, config) {
45
45
  // limited partner must be loaded before person
46
46
  require('./lib/LimitedPartner.js')(mongoose, config);
47
47
 
48
+ // person must be loaded before interaction
49
+ require('./lib/Person.js')(mongoose, config);
50
+
48
51
  // none of these need to be loaded before anything
49
52
  require('./lib/Account.js')(mongoose, config);
50
53
  require('./lib/Activity.js')(mongoose, config);
51
54
  require('./lib/CalendarEvent.js')(mongoose, config);
52
55
  require('./lib/CapTable.js')(mongoose, config);
56
+ require('./lib/Interaction.js')(mongoose, config);
53
57
  require('./lib/Investment.js')(mongoose, config);
54
58
  require('./lib/List.js')(mongoose, config);
55
59
  require('./lib/News.js')(mongoose, config);
56
- require('./lib/Person.js')(mongoose, config);
57
60
  require('./lib/Webhook.js')(mongoose, config);
58
61
 
59
62
  };
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ module.exports = function(mongoose, config) {
4
+
5
+ var Schema = mongoose.Schema;
6
+ var env = process.env.NODE_ENV || 'development';
7
+ var CalendarEvent = mongoose.model('CalendarEvent');
8
+ var Note = mongoose.model('Note');
9
+ var Organization = mongoose.model('Organization');
10
+ var Person = mongoose.model('Person');
11
+
12
+ var Interaction = new Schema({
13
+
14
+ personId: { type: Schema.ObjectId, ref: 'Person', required: true, index: true },
15
+ calendarEventId: { type: Schema.ObjectId, ref: 'CalendarEvent', required: true },
16
+ providerEventId: { type: String, required: true, index: true, trim: true },
17
+ totemCustomerId: { type: Schema.ObjectId, ref: 'Organization', index: true, required: true },
18
+ summary: { type: String, required: true, trim: true },
19
+ startTime: { type: Date, index: true },
20
+ attendees: {
21
+ internal: [{ type: Schema.ObjectId, ref: 'Person', index: true }],
22
+ external: [{ type: Schema.ObjectId, ref: 'Person', index: true }]
23
+ },
24
+ notes: [ { type: Schema.ObjectId, ref: 'Note' } ]
25
+
26
+ });
27
+
28
+ ///////////////////////////////////////
29
+
30
+ Interaction.statics.getForPeople = function getForPeople(personIds, options, cb) {
31
+
32
+ var self = this;
33
+ var query = self.find({
34
+ personId: { $in : personIds },
35
+ totemCustomerId: config.CUSTOMER_ID
36
+ });
37
+
38
+ options.limit = options.limit || -1;
39
+ options.skip = options.skip || -1;
40
+
41
+ query.sort({'startTime': -1});
42
+ query.populate('attendees.internal', 'name title avatarUrl');
43
+ query.populate('attendees.external', 'name title avatarUrl');
44
+ query.populate('notes');
45
+
46
+ if (options.limit >= 0) query.limit(options.limit);
47
+ if (options.skip >= 0) query.skip(options.skip);
48
+
49
+ query.exec(cb);
50
+
51
+ };
52
+
53
+ Interaction.statics.upsert = function upsert(interaction, username, cb) {
54
+
55
+ if (!interaction) { return cb(new Error('Interaction is required'), null); }
56
+ if (!username) { return cb(new Error('Username is required'), null); }
57
+
58
+ interaction.save(cb);
59
+
60
+ };
61
+
62
+ Interaction.set('autoIndex', false);
63
+ Interaction.on('index', function(err) { console.log('error building interaction indexes: ' + err); });
64
+
65
+ mongoose.model('Interaction', Interaction);
66
+
67
+ };
@@ -872,15 +872,7 @@ module.exports = function(mongoose, config) {
872
872
  'people.person.calendarEventSummaries.notes.createdBy': { select: 'name avatarUrl title doNotDisplay' }
873
873
  }
874
874
  })
875
- .exec(function(err, result) {
876
- _.each(result.people, function(peep) {
877
- if (!peep) return;
878
- if (!peep.person) return;
879
- if (!peep.person.calendarEventSummaries) return;
880
- peep.person.calendarEventSummaries = peep.person.calendarEventSummaries.slice(0, 10);
881
- });
882
- return cb(err, result);
883
- });
875
+ .exec(cb);
884
876
 
885
877
  };
886
878
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "1.29.2",
3
+ "version": "1.30.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",