@dhyasama/totem-models 1.33.1 → 2.0.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/.npmignore ADDED
@@ -0,0 +1,14 @@
1
+ lib-cov
2
+ *.seed
3
+ *.log
4
+ *.csv
5
+ *.dat
6
+ *.out
7
+ *.pid
8
+ *.gz
9
+
10
+ npm-debug.log
11
+ node_modules
12
+
13
+ .DS_Store
14
+ .idea
@@ -881,7 +881,7 @@ module.exports = function(mongoose, config) {
881
881
  var self = this;
882
882
 
883
883
  self
884
- .find({'deleted': {$ne: true}})
884
+ .find()
885
885
  .select('name website websiteAliases')
886
886
  .lean()
887
887
  .exec(cb);
@@ -1180,15 +1180,6 @@ module.exports = function(mongoose, config) {
1180
1180
 
1181
1181
  };
1182
1182
 
1183
- Organization.statics.searchByDomain = function(domain, cb) {
1184
-
1185
- domain = utils.getDomain(domain);
1186
-
1187
- this
1188
- .find({ $or: [ { 'websiteAliases': domain }, {'website': domain} ], 'deleted': {$ne: true} })
1189
- .exec(cb);
1190
- };
1191
-
1192
1183
  Organization.statics.setCustomerFunds = function setCustomerFunds(fundids) {
1193
1184
  var self = this;
1194
1185
  self.customerFunds = fundids;
package/lib/Person.js CHANGED
@@ -129,21 +129,6 @@ module.exports = function(mongoose, config) {
129
129
 
130
130
  related: [{ type: Schema.ObjectId, ref: 'Person' }],
131
131
 
132
- calendarEventSummaries: [
133
- {
134
- calendarEventId: { type: Schema.ObjectId, ref: 'CalendarEvent', required: true },
135
- providerEventId: { type: String, required: true, index: true, trim: true },
136
- totemCustomerId: { type: Schema.ObjectId, ref: 'Organization', required: true },
137
- summary: { type: String, required: true, trim: true },
138
- startTime: { type: Date },
139
- attendees: {
140
- internal: [{ type: Schema.ObjectId, ref: 'Person' }],
141
- external: [{ type: Schema.ObjectId, ref: 'Person' }]
142
- },
143
- notes: [ { type: Schema.ObjectId, ref: 'Note' } ]
144
- }
145
- ],
146
-
147
132
  doNotDisplay: { type: Boolean, default: false }
148
133
 
149
134
  });
@@ -212,11 +197,11 @@ module.exports = function(mongoose, config) {
212
197
  var personNotes = this.notes || [];
213
198
  personNotes = _.compact(personNotes);
214
199
 
215
- var eventNotes = _.pluck(this.calendarEventSummaries || [], 'notes');
216
- eventNotes = _.flatten(eventNotes);
217
- eventNotes = _.compact(eventNotes);
200
+ // var eventNotes = _.pluck(this.calendarEventSummaries || [], 'notes');
201
+ // eventNotes = _.flatten(eventNotes);
202
+ // eventNotes = _.compact(eventNotes);
218
203
 
219
- var result = _.sortBy(personNotes.concat(eventNotes), 'createdOn');
204
+ var result = _.sortBy(personNotes, 'createdOn');
220
205
 
221
206
  return result.reverse();
222
207
 
@@ -705,25 +690,11 @@ module.exports = function(mongoose, config) {
705
690
 
706
691
  Person.statics.getById = function (id, cb) {
707
692
 
708
- // this would speed it up
709
- // still need a way to optionally return all though
710
- //.findById(id, { 'calendarEventSummaries': { $slice: 5 } })
711
-
712
693
  this
713
694
  .findById(id)
714
695
  .select('-previous')
715
- .populate('calendarEventSummaries.attendees.external', 'avatarUrl name title doNotDisplay')
716
- .populate('calendarEventSummaries.attendees.internal', 'avatarUrl name title doNotDisplay')
717
- .populate('calendarEventSummaries.notes')
718
696
  .populate('related')
719
697
  .populate('sources.person', 'avatarUrl name title doNotDisplay')
720
- .deepPopulate([
721
- 'calendarEventSummaries.notes.createdBy'
722
- ], {
723
- populate: {
724
- 'calendarEventSummaries.notes.createdBy': { select: 'avatarUrl name' }
725
- }
726
- })
727
698
  .exec(function (err, person) {
728
699
 
729
700
  if (err) return cb(err, null);
@@ -733,12 +704,6 @@ module.exports = function(mongoose, config) {
733
704
  return source.interactions.calendar + source.interactions.email;
734
705
  }).reverse();
735
706
 
736
- // note this gets filtered by customer in post init hook
737
- // sort descending, i.e., reverse chronologically
738
- person.calendarEventSummaries = _.sortBy(person.calendarEventSummaries, function(summary) {
739
- return summary.startTime;
740
- }).reverse();
741
-
742
707
  return cb(null, person);
743
708
 
744
709
  });
@@ -781,36 +746,34 @@ module.exports = function(mongoose, config) {
781
746
 
782
747
  };
783
748
 
784
- Person.statics.getInteractedWith = function getInteractedWith(personId, cb) {
785
-
786
- var self = this;
787
- var query = self.find({
788
- $or: [
789
- { 'calendarEventSummaries.attendees.internal': personId },
790
- { 'calendarEventSummaries.attendees.external': personId }
791
- ]
792
- });
793
- query.exec(cb);
794
-
795
- };
749
+ // Person.statics.getInteractedWith = function getInteractedWith(personId, cb) {
750
+ //
751
+ // var self = this;
752
+ // var query = self.find({
753
+ // $or: [
754
+ // { 'calendarEventSummaries.attendees.internal': personId },
755
+ // { 'calendarEventSummaries.attendees.external': personId }
756
+ // ]
757
+ // });
758
+ // query.exec(cb);
759
+ //
760
+ // };
796
761
 
797
762
  Person.statics.getNotes = function getNotes(personId, cb) {
798
763
 
799
764
  var self = this;
800
765
  var query = self.findById(personId)
801
766
 
802
- query.select('notes calendarEventSummaries')
767
+ query.select('notes')
803
768
  query.populate({
804
769
  path: 'notes',
805
770
  match: { customer: config.CUSTOMER_ID }
806
771
  })
807
772
  query.deepPopulate([
808
- 'notes.createdBy',
809
- 'calendarEventSummaries.notes.createdBy'
773
+ 'notes.createdBy'
810
774
  ], {
811
775
  populate: {
812
- 'notes.createdBy': { select: 'name avatarUrl title' },
813
- 'calendarEventSummaries.notes.createdBy': { select: 'name avatarUrl title' }
776
+ 'notes.createdBy': { select: 'name avatarUrl title' }
814
777
  }
815
778
  })
816
779
  query.sort({'createdOn':-1})
@@ -839,11 +802,11 @@ module.exports = function(mongoose, config) {
839
802
  .exec(cb);
840
803
  };
841
804
 
842
- Person.statics.findByProviderEventId = function (id, cb) {
843
- this
844
- .find({ 'calendarEventSummaries.providerEventId': id })
845
- .exec(cb);
846
- };
805
+ // Person.statics.findByProviderEventId = function (id, cb) {
806
+ // this
807
+ // .find({ 'calendarEventSummaries.providerEventId': id })
808
+ // .exec(cb);
809
+ // };
847
810
 
848
811
  Person.statics.findBySlug = function (slug, cb) {
849
812
  this
@@ -1079,18 +1042,18 @@ module.exports = function(mongoose, config) {
1079
1042
  }, callback);
1080
1043
  };
1081
1044
 
1082
- var removeEventNoteReferences = function removeEventNoteReferences(callback) {
1083
- self.update({
1084
- 'calendarEventSummaries.notes': noteId
1085
- }, {
1086
- $pull: { 'calendarEventSummaries.$.notes' : [noteId] }
1087
- }, callback);
1088
- };
1045
+ // var removeEventNoteReferences = function removeEventNoteReferences(callback) {
1046
+ // self.update({
1047
+ // 'calendarEventSummaries.notes': noteId
1048
+ // }, {
1049
+ // $pull: { 'calendarEventSummaries.$.notes' : [noteId] }
1050
+ // }, callback);
1051
+ // };
1089
1052
 
1090
1053
  async.series([
1091
1054
  Note.delete.bind(Note, noteId),
1092
1055
  removePersonNoteReferences,
1093
- removeEventNoteReferences
1056
+ //removeEventNoteReferences
1094
1057
  ], function(err, results) {
1095
1058
  return cb(err, null);
1096
1059
  });
@@ -1167,53 +1130,11 @@ module.exports = function(mongoose, config) {
1167
1130
  self.contact.email = thereCanOnlyBeOne(self.contact.email);
1168
1131
  self.contact.phone = thereCanOnlyBeOne(self.contact.phone);
1169
1132
 
1170
- // Reset counters so we can calc from scratch
1171
- _.each(self.sources, function(source) {
1172
- source.interactions.calendar = 0;
1173
- });
1174
-
1175
- _.each(self.calendarEventSummaries, function(ces) {
1176
-
1177
- var customerId = ces.totemCustomerId;
1178
-
1179
- // Each attendee from the customer is a source
1180
- _.each(ces.attendees.internal, function(attendee) {
1181
-
1182
- var aid = mongoose.Types.ObjectId.isValid(attendee) ? attendee : attendee._id;
1183
-
1184
- // Check if this attendee has already been added as a source
1185
- var match = _.find(self.sources, function(source) {
1186
- // It's a match if both person and customer ids are a match
1187
- var pid = mongoose.Types.ObjectId.isValid(source.person) ? source.person : source.person._id;
1188
- var cid = mongoose.Types.ObjectId.isValid(source.customer) ? source.customer : source.customer._id;
1189
- return pid.toString() == aid.toString() && cid.toString() == customerId.toString();
1190
- });
1191
-
1192
- // If source already added, increment counter
1193
- if (match) { match.interactions.calendar += 1; }
1194
-
1195
- // Otherwise add the source
1196
- else {
1197
- self.sources.push({
1198
- person: aid,
1199
- customer: customerId,
1200
- interactions: { calendar: 1 }
1201
- });
1202
- }
1203
-
1204
- });
1205
-
1206
- });
1207
-
1208
1133
  // must have person and customer refs
1209
- self.sources = _.reject(self.sources, function(source) {
1210
- return !source.person || !source.customer;
1211
- });
1134
+ self.sources = _.reject(self.sources, function(source) { return !source.person || !source.customer; });
1212
1135
 
1213
1136
  // dedupe
1214
- self.sources = _.uniq(self.sources, function(source) {
1215
- return source.person.toString() + source.customer.toString();
1216
- });
1137
+ self.sources = _.uniq(self.sources, function(source) { return source.person.toString() + source.customer.toString(); });
1217
1138
 
1218
1139
  next();
1219
1140
 
@@ -1224,16 +1145,6 @@ module.exports = function(mongoose, config) {
1224
1145
  var self = this;
1225
1146
  var CUSTOMER_ID = config.CUSTOMER_ID;
1226
1147
 
1227
- var protectCalendarEventData = function protectCalendarEventData(person) {
1228
-
1229
- if (CUSTOMER_ID == 'GLOBAL_PROCESS') return;
1230
-
1231
- person.calendarEventSummaries = _.reject(person.calendarEventSummaries, function(event) {
1232
- return event.totemCustomerId != CUSTOMER_ID;
1233
- });
1234
-
1235
- };
1236
-
1237
1148
  var protectSources = function protectSources(person) {
1238
1149
 
1239
1150
  if (CUSTOMER_ID == 'GLOBAL_PROCESS') return;
@@ -1245,19 +1156,8 @@ module.exports = function(mongoose, config) {
1245
1156
 
1246
1157
  };
1247
1158
 
1248
- protectCalendarEventData(self);
1249
1159
  protectSources(self);
1250
1160
 
1251
- // // must have person and customer refs
1252
- // self.sources = _.reject(self.sources, function(source) {
1253
- // return !source.person || !source.customer;
1254
- // });
1255
- //
1256
- // // dedupe
1257
- // self.sources = _.uniq(self.sources, function(source) {
1258
- // return source.person.toString() && source.customer.toString();
1259
- // });
1260
-
1261
1161
  });
1262
1162
 
1263
1163
  var deepPopulate = require('mongoose-deep-populate')(mongoose);