@dhyasama/totem-models 7.57.0 → 8.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/lib/Financials.js CHANGED
@@ -10,7 +10,6 @@
10
10
  module.exports = function(mongoose, config) {
11
11
 
12
12
  var Schema = mongoose.Schema;
13
- var async = require('async');
14
13
  var _ = require('underscore');
15
14
  var moment = require('moment');
16
15
 
@@ -28,6 +27,8 @@ module.exports = function(mongoose, config) {
28
27
 
29
28
  uuid: { type: String },
30
29
 
30
+ campaignId: { type: String },
31
+
31
32
  managedServices: { type: Boolean, default: false, required: true },
32
33
 
33
34
  status: { type: String },
@@ -114,18 +115,16 @@ module.exports = function(mongoose, config) {
114
115
 
115
116
  submittedOn: { type: Date, index: false },
116
117
  submittedBy: { type: String, trim: true },
117
-
118
118
  reviewedOn: { type: Date, index: false },
119
- rejection: { type: String, trim: true },
120
119
 
121
120
  notifications: {
122
121
 
123
122
  company: {
124
123
 
125
- sendTo: [{
124
+ sendTo: {
126
125
  email: { type: String, trim: true },
127
126
  name: { type: String, trim: true }
128
- }],
127
+ },
129
128
 
130
129
  initial: {
131
130
  sendOn: { type: Date, required: false },
@@ -134,18 +133,17 @@ module.exports = function(mongoose, config) {
134
133
  status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
135
134
  },
136
135
 
137
- reminders: [{
136
+ reminder: {
138
137
  sendOn: { type: Date, required: false },
139
138
  sentOn: { type: Date, required: false },
140
139
  postmarkMessageId: { type: String, trim: true },
141
140
  status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
142
- }],
141
+ },
143
142
 
144
- rejections: [{
145
- sendOn: { type: Date, required: false },
146
- sentOn: { type: Date, required: false },
143
+ history: [{
144
+ email: { type: String, trim: true },
147
145
  postmarkMessageId: { type: String, trim: true },
148
- status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
146
+ status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
149
147
  }]
150
148
 
151
149
  },
@@ -182,6 +180,8 @@ module.exports = function(mongoose, config) {
182
180
 
183
181
  });
184
182
 
183
+
184
+
185
185
  ///////////////////////////////////////////////////////////////////////////////////////
186
186
  // METHODS
187
187
  // Methods operate on a single document
@@ -196,9 +196,9 @@ module.exports = function(mongoose, config) {
196
196
 
197
197
  Financials.statics.getByOrg = function getByOrg(customerId, orgId, cb) {
198
198
 
199
- var self = this;
199
+ let self = this;
200
200
 
201
- var query = self.findOne({
201
+ let query = self.findOne({
202
202
  'customer': customerId,
203
203
  'organization': orgId
204
204
  }).populate({
@@ -206,15 +206,34 @@ module.exports = function(mongoose, config) {
206
206
  match: { customer: customerId }
207
207
  });
208
208
 
209
+ // No need to scrub because population matched on customer id
210
+
211
+ query.exec(cb);
212
+
213
+ };
214
+
215
+ Financials.statics.getByPostmarkMessageId = function getByPostmarkMessageId(postmarkMessageId, cb) {
216
+
217
+ let self = this;
218
+
219
+ let query = self.findOne({
220
+ $or: [
221
+ { 'snapshots.notifications.company.initial.postmarkMessageId': postmarkMessageId },
222
+ { 'snapshots.notifications.company.reminder.postmarkMessageId': postmarkMessageId }
223
+ ]
224
+ });
225
+
226
+ // No population so no need to scrub
227
+
209
228
  query.exec(cb);
210
229
 
211
230
  };
212
231
 
213
232
  Financials.statics.getByUUID = function getByUUID(customerId, uuid, cb) {
214
233
 
215
- var self = this;
234
+ let self = this;
216
235
 
217
- var query = self.findOne({
236
+ let query = self.findOne({
218
237
  'customer': customerId,
219
238
  'snapshots.uuid': uuid
220
239
  });
@@ -226,146 +245,114 @@ module.exports = function(mongoose, config) {
226
245
  match: { customer: customerId }
227
246
  });
228
247
 
248
+ // No need to scrub because population matched on customer id
249
+
229
250
  query.exec(cb);
230
251
 
231
252
  };
232
253
 
233
- Financials.statics.getByPostmarkMessageId = function getByPostmarkMessageId(postmarkMessageId, cb) {
254
+ Financials.statics.getForCampaign = function getForCampaign(customerId, cb) {
234
255
 
235
- var self = this;
256
+ let self = this;
236
257
 
237
- var query = self.findOne({
238
- $or: [
239
- { 'snapshots.notifications.company.initial.postmarkMessageId': postmarkMessageId },
240
- { 'snapshots.notifications.company.reminders.postmarkMessageId': postmarkMessageId },
241
- { 'snapshots.notifications.company.rejections.postmarkMessageId': postmarkMessageId },
242
- ]
258
+ let query = self.find({
259
+ 'customer': customerId,
260
+ 'notification.contact.exclude': { $ne: true }, // null, false, or non-existing field
261
+ 'notification.contact.email': { $ne: null } // field exists and has a value
243
262
  });
244
263
 
264
+ // No population so no need to scrub
265
+
245
266
  query.exec(cb);
246
267
 
247
268
  };
248
269
 
249
- Financials.statics.getInitialUUIDsToSend = function getInitialUUIDsToSend(cb) {
270
+ Financials.statics.getForCustomer = function getForCustomer(customerId, cb) {
250
271
 
251
- var self = this;
252
- var now = new Date();
272
+ let self = this;
253
273
 
254
- var query = self.find({
255
- 'snapshots': {
256
- $elemMatch: {
257
- 'notifications.company.sendTo': { $gt: [] },
258
- 'notifications.company.initial.sendOn': { $lte: now },
259
- 'notifications.company.initial.sentOn': null
260
- }
261
- }
274
+ let query = self.find({
275
+ 'customer': customerId
262
276
  });
263
277
 
264
- query.exec(function(err, result) {
265
-
266
- if (err) { return cb(err, null); }
267
-
268
- var snapshots = _.pluck(result || [], 'snapshots');
278
+ // No population so no need to scrub
269
279
 
270
- snapshots = _.flatten(snapshots);
271
-
272
- snapshots = _.filter(snapshots, function(snapshot) {
273
-
274
- var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
275
- var hasUnsentSendOnLessThanNow = snapshot.notifications.company.initial.sendOn < now && !snapshot.notifications.company.initial.sentOn;
276
-
277
- return hasRecipients && hasUnsentSendOnLessThanNow;
278
-
279
- });
280
-
281
- return cb(null, _.pluck(snapshots, 'uuid'));
282
-
283
- });
280
+ query.exec(cb);
284
281
 
285
282
  };
286
283
 
287
- Financials.statics.getReminderUUIDsToSend = function getReminderUUIDsToSend(cb) {
284
+ Financials.statics.getManagedServicesForReview = function getManagedServicesForReview(customerId, cb) {
288
285
 
289
- var self = this;
290
- var now = new Date();
286
+ let self = this;
291
287
 
292
- var query = self.find({
288
+ let query = self.find({
289
+ 'customer': customerId,
293
290
  'snapshots': {
294
291
  $elemMatch: {
295
- 'notifications.company.sendTo': { $gt: [] },
296
- 'notifications.company.reminders.sendOn': { $lte: now },
297
- 'notifications.company.reminders.sentOn': null,
298
- "$or": [
299
- {
300
- "submittedOn": null,
301
- },
302
- {
303
- "submittedOn": { $ne: null },
304
- "rejection": { $ne: null }
305
- }
306
- ]
292
+ 'managedServices': true,
293
+ 'submittedOn': { $ne: null },
294
+ 'reviewedOn': null
307
295
  }
308
296
  }
309
297
  });
310
298
 
311
- query.exec(function(err, result) {
312
-
313
- if (err) { return cb(err, null); }
299
+ // No population so no need to scrub
314
300
 
315
- var snapshots = _.pluck(result || [], 'snapshots');
301
+ query.exec(function(err, result) {
316
302
 
303
+ let snapshots = _.pluck(result || [], 'snapshots');
317
304
  snapshots = _.flatten(snapshots);
318
305
 
319
306
  snapshots = _.filter(snapshots, function(snapshot) {
320
307
 
321
- var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
322
- var hasUnsentSendOnLessThanNow = _.find(snapshot.notifications.company.reminders, function(reminder) {
323
- return reminder.sendOn < now && !reminder.sentOn;
324
- });
325
- var hasNotBeenSubmitted = !snapshot.submittedOn;
326
- var hasBeenRejected = snapshot.submittedOn && snapshot.rejection;
308
+ let bool = snapshot.managedServices;
309
+ bool = bool && snapshot.submittedOn;
310
+ bool = bool && !snapshot.reviewedOn;
327
311
 
328
- return hasRecipients && hasUnsentSendOnLessThanNow && (hasNotBeenSubmitted || hasBeenRejected);
312
+ return bool;
329
313
 
330
314
  });
331
315
 
332
- return cb(null, _.pluck(snapshots, 'uuid'));
316
+ if (err) { return cb(err, null); }
317
+ return cb(null, snapshots);
333
318
 
334
319
  });
335
320
 
336
321
  };
337
322
 
338
- Financials.statics.getRejectionUUIDsToSend = function getRejectionUUIDsToSend(cb) {
323
+ Financials.statics.getUUIDsToSendInitial = function getUUIDsToSendInitial(cb) {
339
324
 
340
- var self = this;
341
- var now = new Date();
325
+ let self = this;
326
+ let now = new Date();
342
327
 
343
- var query = self.find({
328
+ let query = self.find({
344
329
  'snapshots': {
345
330
  $elemMatch: {
346
- 'notifications.company.sendTo': { $gt: [] },
347
- 'notifications.company.rejections.sendOn': { $lte: now },
348
- 'notifications.company.rejections.sentOn': null
331
+ 'notifications.company.sendTo.email': { $ne: null },
332
+ 'notifications.company.initial.sendOn': { $lte: now },
333
+ 'notifications.company.initial.sentOn': null,
334
+ 'submittedOn': null
349
335
  }
350
336
  }
351
337
  });
352
338
 
339
+ // No population so no need to scrub
340
+
353
341
  query.exec(function(err, result) {
354
342
 
355
343
  if (err) { return cb(err, null); }
356
344
 
357
- var snapshots = _.pluck(result || [], 'snapshots');
345
+ let snapshots = _.pluck(result || [], 'snapshots');
358
346
 
359
347
  snapshots = _.flatten(snapshots);
360
348
 
361
349
  snapshots = _.filter(snapshots, function(snapshot) {
362
350
 
363
- var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
364
- var hasUnsentSendOnLessThanNow = _.find(snapshot.notifications.company.rejections, function(rejection) {
365
- return rejection.sendOn < now && !rejection.sentOn;
366
- });
351
+ let bool = !!snapshot.notifications.company.sendTo.email;
352
+ bool = bool && snapshot.notifications.company.initial.sendOn < now;
353
+ bool = bool && !snapshot.notifications.company.initial.sentOn;
367
354
 
368
- return hasRecipients && hasUnsentSendOnLessThanNow;
355
+ return bool;
369
356
 
370
357
  });
371
358
 
@@ -375,76 +362,46 @@ module.exports = function(mongoose, config) {
375
362
 
376
363
  };
377
364
 
378
- Financials.statics.getForCustomer = function getForCustomer(customerId, cb) {
365
+ Financials.statics.getUUIDsToSendReminder = function getUUIDsToSendReminder(cb) {
379
366
 
380
- var self = this;
367
+ let self = this;
368
+ let now = new Date();
381
369
 
382
- var query = self.find({
383
- 'customer': customerId
384
- });
385
-
386
- query.exec(cb);
387
-
388
- };
389
-
390
- Financials.statics.getManagedServicesForReview = function getManagedServicesForReview(customerId, cb) {
391
-
392
- var self = this;
393
-
394
- var query = self.find({
395
- 'customer': customerId,
370
+ let query = self.find({
396
371
  'snapshots': {
397
372
  $elemMatch: {
398
- 'managedServices': true,
399
- 'submittedOn': { $ne: null },
400
- 'reviewedOn': null
373
+ 'notifications.company.sendTo.email': { $ne: null },
374
+ 'notifications.company.reminder.sendOn': { $lte: now },
375
+ 'notifications.company.reminder.sentOn': null,
376
+ 'submittedOn': null
401
377
  }
402
378
  }
403
379
  });
404
380
 
405
- query.populate('organization', 'name');
406
-
407
- query.exec(function(err, results) {
408
-
409
- var snapshots = [];
381
+ // No population so no need to scrub
410
382
 
411
- _.each(results, function(result) {
412
- _.each(result.snapshots, function(snapshot) {
383
+ query.exec(function(err, result) {
413
384
 
414
- var isManagedServices = snapshot.managedServices;
415
- var isSubmitted = snapshot.submittedOn;
416
- var isNotReviewed = !snapshot.reviewedOn;
385
+ if (err) { return cb(err, null); }
417
386
 
418
- if(isManagedServices && isSubmitted && isNotReviewed) {
419
- snapshots.push({
420
- organization: result.organization.name,
421
- snapshot: snapshot
422
- });
423
- }
387
+ let snapshots = _.pluck(result || [], 'snapshots');
424
388
 
425
- });
426
- });
389
+ snapshots = _.flatten(snapshots);
427
390
 
428
- if (err) { return cb(err, null); }
429
- return cb(null, snapshots);
391
+ snapshots = _.filter(snapshots, function(snapshot) {
430
392
 
431
- });
393
+ let bool = !!snapshot.notifications.company.sendTo.email;
394
+ bool = bool && snapshot.notifications.company.reminder.sendOn < now;
395
+ bool = bool && !snapshot.notifications.company.reminder.sentOn;
432
396
 
433
- };
397
+ return bool;
434
398
 
435
- Financials.statics.getToSend = function getToSend(uuid, cb) {
399
+ });
436
400
 
437
- var self = this;
401
+ return cb(null, _.pluck(snapshots, 'uuid'));
438
402
 
439
- var query = self.findOne({
440
- 'snapshots.uuid': uuid
441
403
  });
442
404
 
443
- query.populate('organization', 'name logoUrl');
444
- query.populate('customer', 'name logoUrl customer.totemUrl');
445
-
446
- query.exec(cb);
447
-
448
405
  };
449
406
 
450
407
  Financials.statics.removeCustomerFinancials = function removeCustomerFinancials(customerId, cb) {
@@ -452,7 +409,9 @@ module.exports = function(mongoose, config) {
452
409
  // this is only used to wipe out financials created by the google sheet import process
453
410
  // we do NOT want to delete any financials submitted via forms generated directly from the app
454
411
 
455
- var self = this;
412
+ let self = this;
413
+
414
+ // No population so no need to scrub
456
415
 
457
416
  self
458
417
  .update(
@@ -465,6 +424,7 @@ module.exports = function(mongoose, config) {
465
424
 
466
425
  Financials.statics.upsert = function upsert(financials, cb) {
467
426
 
427
+ if (!cb) { throw new Error('cb is required'); }
468
428
  if (!financials) { return cb(new Error('financials is required'), null); }
469
429
 
470
430
  // Required for mixed types
@@ -481,6 +441,8 @@ module.exports = function(mongoose, config) {
481
441
  financials.markModified('investingActivities.breakdown');
482
442
  financials.markModified('financingActivities.breakdown');
483
443
 
444
+ // No population so no need to scrub
445
+
484
446
  financials.save(cb);
485
447
 
486
448
  };
@@ -501,24 +463,17 @@ module.exports = function(mongoose, config) {
501
463
 
502
464
  if(!snapshot) return;
503
465
 
504
- var isManagedServices = snapshot.managedServices;
505
- var isSubmitted = snapshot.submittedOn;
506
- var isReviewed = snapshot.reviewedOn;
507
- var isRejected = snapshot.rejection;
508
-
509
466
  // no uuid means the data was captured from the google sheet
510
- if((!snapshot.uuid) || (!isManagedServices && isSubmitted) || (isManagedServices && isReviewed)) {
467
+ if((!snapshot.uuid) || (!snapshot.managedServices && snapshot.submittedOn) || (snapshot.managedServices && snapshot.reviewedOn)) {
511
468
  snapshot.status = 'Completed';
512
469
  snapshot.action = null;
513
470
  }
514
471
 
515
- else if(snapshot.notifications.company && snapshot.notifications.company.initial && snapshot.notifications.company.initial.sendOn) {
516
-
517
- var latestReminder = _.max(snapshot.notifications.company.reminders, function(r) { return new Date(r.sendOn); });
518
-
519
- var isScheduled = snapshot.notifications.company.initial.sendOn && moment().isBefore(moment(snapshot.notifications.company.initial.sendOn));
520
- var isOverdue = latestReminder.sendOn && moment().subtract(14, 'd').isAfter(moment(latestReminder.sendOn));
472
+ else if(snapshot.notifications.company.initial.sendOn) {
521
473
 
474
+ var isScheduled = moment().isBefore(moment(snapshot.notifications.company.initial.sendOn));
475
+ var isOverdue = moment().subtract(30, 'd').isAfter(moment(snapshot.notifications.company.reminder.sendOn || snapshot.notifications.company.initial.sendOn));
476
+
522
477
  if(isScheduled) {
523
478
  snapshot.status = 'Scheduled';
524
479
  snapshot.action = null;
@@ -531,10 +486,9 @@ module.exports = function(mongoose, config) {
531
486
 
532
487
  else {
533
488
  snapshot.status = 'In Progress';
534
- if(isManagedServices && isSubmitted && !isRejected) snapshot.action = 'Review';
535
- else if(isManagedServices && isSubmitted && isRejected) snapshot.action = 'Rejected';
536
- else if(latestReminder.sentOn) snapshot.action = latestReminder.status;
537
- else snapshot.action = snapshot.notifications.company.initial.status;
489
+ if(snapshot.managedServices && snapshot.submittedOn) snapshot.action = 'Review';
490
+ else if(snapshot.notifications.company.reminder.status) snapshot.action = snapshot.notifications.company.reminder.status;
491
+ else if (snapshot.notifications.company.initial.status) snapshot.action = snapshot.notifications.company.initial.status;
538
492
  }
539
493
 
540
494
  }
@@ -550,22 +504,11 @@ module.exports = function(mongoose, config) {
550
504
 
551
505
  });
552
506
 
553
- Financials.post('init', function(doc, next) {
554
-
555
- return next();
556
-
557
- });
558
-
559
- Financials.post('remove', function(doc) {
560
- // todo
561
- });
562
-
563
507
  ///////////////////////////////////////////////////////////////////////////////////////
564
508
  // CONFIG
565
509
  ///////////////////////////////////////////////////////////////////////////////////////
566
510
 
567
511
  Financials.set('toJSON', { virtuals: true });
568
- Financials.set('usePushEach', true);
569
512
  Financials.set('autoIndex', false);
570
513
 
571
514
  Financials.on('index', function(err) { console.log('error building financials indexes: ' + err); });
package/lib/Flag.js CHANGED
@@ -23,6 +23,14 @@ module.exports = function(mongoose, config) {
23
23
 
24
24
  Flag.statics.createForModel = function(flag, Model, modelId, cb) {
25
25
 
26
+ if (!cb) { throw new Error('cb is required'); }
27
+ if (!flag) { throw new Error('flag is required'); }
28
+ if (!Model) { throw new Error('Model is required'); }
29
+ if (!modelId) { throw new Error('modelId is required'); }
30
+ if (!mongoose.Types.ObjectId.isValid(modelId)) { return cb(new Error('modelId is not a valid ObjectId'), null); }
31
+
32
+ const self = this;
33
+
26
34
  var addToModel = function(err, createdFlag) {
27
35
  if (err) return cb(err, null);
28
36
  Model.findByIdAndUpdate(modelId, { $push: { flags: createdFlag }}, { new: true, upsert: false }, function(err, addedTo) {
@@ -34,24 +42,31 @@ module.exports = function(mongoose, config) {
34
42
  };
35
43
 
36
44
  flag.createdOn = new Date();
37
- flag.customer = config.CUSTOMER_ID;
38
45
 
39
- this.create(flag, addToModel);
46
+ self.create(flag, addToModel);
40
47
 
41
48
  };
42
49
 
43
- Flag.statics.delete = function(flagId, cb) {
50
+ Flag.statics.delete = function(flagId, customerId, cb) {
44
51
 
45
- var self = this;
52
+ if (!cb) { throw new Error('cb is required'); }
53
+ if (!flagId) { throw new Error('flagId is required'); }
54
+ if (!mongoose.Types.ObjectId.isValid(flagId)) { return cb(new Error('flagId is not a valid ObjectId'), null); }
55
+ if (!customerId) { return cb(new Error('customerId is required'), null); }
56
+ if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
57
+
58
+ const self = this;
46
59
 
47
60
  // Not strictly necessary but provides verification that the flag being deleted belongs to the customer doing the deleting
48
- self.findOne({
61
+ let query = self.findOne({
49
62
  '_id': flagId,
50
- 'customer': config.CUSTOMER_ID
51
- }, function(err, flag) {
63
+ 'customer': customerId
64
+ });
52
65
 
53
- if (err) return cb(err, null);
54
- else if (!flag) return cb(null, null);
66
+ query.exec(function(err, flag) {
67
+
68
+ if (err) { return cb(err, null); }
69
+ else if (!flag) { return cb(null, null); }
55
70
 
56
71
  flag.remove(cb);
57
72
 
@@ -60,10 +75,19 @@ module.exports = function(mongoose, config) {
60
75
  };
61
76
 
62
77
  Flag.statics.getById = function(id, cb) {
63
- this.findOne({
64
- '_id': id,
65
- 'customer': config.CUSTOMER_ID
66
- }).exec(cb);
78
+
79
+ if (!cb) { throw new Error('cb is required'); }
80
+ if (!id) { throw new Error('id is required'); }
81
+ if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
82
+
83
+ const self = this;
84
+
85
+ let query = self.findById({
86
+ '_id': id
87
+ });
88
+
89
+ query.exec(cb);
90
+
67
91
  };
68
92
 
69
93
  Flag.statics.modifyById = function(id, update, cb) {
@@ -95,7 +119,6 @@ module.exports = function(mongoose, config) {
95
119
  });
96
120
 
97
121
  Flag.set('autoIndex', false);
98
- Flag.set('usePushEach', true);
99
122
  Flag.on('index', function(err) { console.log('error building Flag indexes: ' + err); });
100
123
 
101
124
  mongoose.model('Flag', Flag);
package/lib/Fund.js CHANGED
@@ -5,23 +5,19 @@ module.exports = function(mongoose, config) {
5
5
  var Schema = mongoose.Schema;
6
6
  var Round = mongoose.model('Round');
7
7
  var _ = require('underscore');
8
- var env = process.env.NODE_ENV || 'development';
9
8
 
10
9
  var Fund = new Schema({
10
+
11
11
  name: { type: String, required: true, unique: true },
12
12
  slug: { type: String, required: true, unique: true },
13
13
  shortName: { type: String, required: true },
14
- abbreviation: { type: String },
14
+ abbreviation: { type: String, required: true },
15
15
  spv: { type: Boolean, default: false },
16
16
  hexColorCode: { type: String, required: true, default: '#cccccc' },
17
17
  closeDate: { type: Date },
18
18
  amount: { type: Number },
19
- crunchbase: { uuid: { type: String, default: '', unique: true } },
20
- transactions: [{
21
- type: { type: String, enum: ['fees', 'expenses', 'carry'] },
22
- amount: { type: Number, default: 0 },
23
- date: { type: Date, default: null },
24
- }],
19
+ crunchbase: { uuid: { type: String, default: '', unique: true } }
20
+
25
21
  });
26
22
 
27
23
  /************* BASIC FIELDS **********************/
@@ -152,7 +148,8 @@ module.exports = function(mongoose, config) {
152
148
  if (!query) return cb(null, []);
153
149
 
154
150
  var conditions = {
155
- 'name': new RegExp(query, "i")
151
+ 'name': new RegExp(query.query, "i"),
152
+ 'deleted': {$ne: true}
156
153
  };
157
154
 
158
155
  this
@@ -171,31 +168,7 @@ module.exports = function(mongoose, config) {
171
168
 
172
169
  };
173
170
 
174
- Fund.statics.removeTransactions = function removeTransactions(cb) {
175
-
176
- var self = this;
177
-
178
- var query = self.update(
179
- { $set: { transactions: [] } },
180
- { multi : true }
181
- );
182
- query.exec(cb);
183
-
184
- };
185
-
186
- Fund.post('remove', function(doc) {
187
- // Debt.debts.internal.fund
188
- // Document.fundInvolved
189
- // Investment.internal.fund
190
- // Investor.funds
191
- // LimitedPartner.fundsInvested.fund
192
- // Message.fundsInvolved
193
- // News.fundsInvolved
194
- // PortfolioCompany.fundsInvested
195
- });
196
-
197
171
  Fund.set('autoIndex', false);
198
- Fund.set('usePushEach', true);
199
172
  Fund.on('index', function(err) { console.log('error building fund indexes: ' + err); });
200
173
 
201
174
  mongoose.model('Fund', Fund);