@dhyasama/totem-models 1.30.2 → 1.31.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.
@@ -8,18 +8,18 @@ module.exports = function(mongoose, config) {
8
8
  var Note = mongoose.model('Note');
9
9
  var Organization = mongoose.model('Organization');
10
10
  var Person = mongoose.model('Person');
11
+ var moment = require('moment');
11
12
 
12
13
  var Interaction = new Schema({
13
14
 
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 },
15
+ calendarEventId: { type: Schema.ObjectId, ref: 'CalendarEvent', required: true }, // the event from the original pull
16
+ providerEventId: { type: String, required: true, index: true, trim: true }, // unique id from the calendar provider
17
17
  totemCustomerId: { type: Schema.ObjectId, ref: 'Organization', index: true, required: true },
18
18
  summary: { type: String, required: true, trim: true },
19
19
  startTime: { type: Date, index: true },
20
20
  attendees: {
21
- internal: [{ type: Schema.ObjectId, ref: 'Person', index: true }],
22
- external: [{ type: Schema.ObjectId, ref: 'Person', index: true }]
21
+ internal: [{ type: Schema.ObjectId, ref: 'Person', index: true }], // people from customer
22
+ external: [{ type: Schema.ObjectId, ref: 'Person', index: true }] // everyone else
23
23
  },
24
24
  notes: [ { type: Schema.ObjectId, ref: 'Note' } ]
25
25
 
@@ -27,33 +27,65 @@ module.exports = function(mongoose, config) {
27
27
 
28
28
  ///////////////////////////////////////
29
29
 
30
+ Interaction.statics.delete = function(providerEventId, totemCustomerId, cb) {
31
+
32
+ var self = this;
33
+
34
+ self.findOneAndRemove({
35
+ 'providerEventId': providerEventId,
36
+ 'totemCustomerId': totemCustomerId
37
+ }, cb);
38
+
39
+ };
40
+
41
+ Interaction.statics.getForCustomer = function getForCustomer(cb) {
42
+
43
+ var self = this;
44
+ var query = self.find({ totemCustomerId: config.CUSTOMER_ID });
45
+
46
+ query.exec(cb);
47
+
48
+ };
49
+
30
50
  Interaction.statics.getForPeople = function getForPeople(personIds, options, cb) {
31
51
 
32
52
  var self = this;
33
- var query = self.find({
34
- personId: { $in : personIds },
35
- totemCustomerId: config.CUSTOMER_ID
36
- });
37
53
 
38
54
  options.limit = options.limit || -1;
39
55
  options.skip = options.skip || -1;
40
56
 
41
- query.sort({'startTime': -1});
57
+ // Note if you are using limit and skip, i.e., paging,
58
+ // then don't add these options in the middle of paging
59
+ // because it will alter the pages
60
+ options.sort = options.sort || {'startTime': -1};
61
+ options.before = options.before || moment().toISOString();
62
+ options.after = options.after || moment().subtract(1, 'year').toISOString();
63
+
64
+ var query = self.find({ totemCustomerId: config.CUSTOMER_ID });
65
+
66
+ query.where({'attendees.external': { $in : personIds }});
67
+ query.where({ startTime: { $gte: options.after }});
68
+ query.where({ startTime: { $lte: options.before }});
42
69
  query.populate('attendees.internal', 'name title avatarUrl');
43
70
  query.populate('attendees.external', 'name title avatarUrl');
44
71
  query.populate('notes');
72
+ query.sort(options.sort);
45
73
 
74
+ if (options.attendee) { query.where({'attendees.internal': options.attendee}); }
46
75
  if (options.limit >= 0) query.limit(options.limit);
47
76
  if (options.skip >= 0) query.skip(options.skip);
48
77
 
49
78
  query.exec(cb);
50
79
 
80
+ // todo
81
+ //options.includeRecurring = options.includeRecurring || true;
82
+ //query.where({ recurring: options.recurring });
83
+
51
84
  };
52
85
 
53
- Interaction.statics.upsert = function upsert(interaction, username, cb) {
86
+ Interaction.statics.upsert = function upsert(interaction, cb) {
54
87
 
55
88
  if (!interaction) { return cb(new Error('Interaction is required'), null); }
56
- if (!username) { return cb(new Error('Username is required'), null); }
57
89
 
58
90
  interaction.save(cb);
59
91
 
package/lib/Person.js CHANGED
@@ -636,6 +636,12 @@ module.exports = function(mongoose, config) {
636
636
 
637
637
  };
638
638
 
639
+ Person.statics.searchByEmail = function(email, cb) {
640
+ this
641
+ .find({ 'contact.email.email': email, 'deleted': {$ne: true} })
642
+ .exec(cb);
643
+ };
644
+
639
645
  Person.statics.findDupes = function(person, options, cb) {
640
646
 
641
647
  if (!cb) throw new Error('cb is required');
package/package-lock.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "1.26.1",
3
+ "version": "1.30.3",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "1.30.2",
3
+ "version": "1.31.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
@@ -21,6 +21,7 @@
21
21
  "bcrypt": "^0.8.0",
22
22
  "bluebird": "^3.5.0",
23
23
  "escape-string-regexp": "^1.0.5",
24
+ "moment": "^2.22.1",
24
25
  "mongoose-deep-populate": "^3.0.0",
25
26
  "mongoose-filter-denormalize": "^0.2.1",
26
27
  "mongoose-post-find": "0.0.2",