@dhyasama/totem-models 7.58.0 → 8.0.1

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,150 +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 hasBeenSubmitted = snapshot.submittedOn;
326
- var hasBeenRejected = snapshot.rejection;
308
+ let bool = snapshot.managedServices;
309
+ bool = bool && snapshot.submittedOn;
310
+ bool = bool && !snapshot.reviewedOn;
327
311
 
328
- return hasRecipients && hasUnsentSendOnLessThanNow && ((!hasBeenSubmitted) || (hasBeenSubmitted && 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,
349
- "submittedOn": { $ne: null },
350
- "rejection": { $ne: null }
331
+ 'notifications.company.sendTo.email': { $ne: null },
332
+ 'notifications.company.initial.sendOn': { $lte: now },
333
+ 'notifications.company.initial.sentOn': null,
334
+ 'submittedOn': null
351
335
  }
352
336
  }
353
337
  });
354
338
 
339
+ // No population so no need to scrub
340
+
355
341
  query.exec(function(err, result) {
356
342
 
357
343
  if (err) { return cb(err, null); }
358
344
 
359
- var snapshots = _.pluck(result || [], 'snapshots');
345
+ let snapshots = _.pluck(result || [], 'snapshots');
360
346
 
361
347
  snapshots = _.flatten(snapshots);
362
348
 
363
349
  snapshots = _.filter(snapshots, function(snapshot) {
364
350
 
365
- var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
366
- var hasUnsentSendOnLessThanNow = _.find(snapshot.notifications.company.rejections, function(rejection) {
367
- return rejection.sendOn < now && !rejection.sentOn;
368
- });
369
- var hasBeenSubmitted = snapshot.submittedOn;
370
- var hasBeenRejected = snapshot.rejection;
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;
371
354
 
372
- return hasRecipients && hasUnsentSendOnLessThanNow && hasBeenSubmitted && hasBeenRejected;
355
+ return bool;
373
356
 
374
357
  });
375
358
 
@@ -379,76 +362,46 @@ module.exports = function(mongoose, config) {
379
362
 
380
363
  };
381
364
 
382
- Financials.statics.getForCustomer = function getForCustomer(customerId, cb) {
365
+ Financials.statics.getUUIDsToSendReminder = function getUUIDsToSendReminder(cb) {
383
366
 
384
- var self = this;
367
+ let self = this;
368
+ let now = new Date();
385
369
 
386
- var query = self.find({
387
- 'customer': customerId
388
- });
389
-
390
- query.exec(cb);
391
-
392
- };
393
-
394
- Financials.statics.getManagedServicesForReview = function getManagedServicesForReview(customerId, cb) {
395
-
396
- var self = this;
397
-
398
- var query = self.find({
399
- 'customer': customerId,
370
+ let query = self.find({
400
371
  'snapshots': {
401
372
  $elemMatch: {
402
- 'managedServices': true,
403
- 'submittedOn': { $ne: null },
404
- '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
405
377
  }
406
378
  }
407
379
  });
408
380
 
409
- query.populate('organization', 'name');
410
-
411
- query.exec(function(err, results) {
412
-
413
- var snapshots = [];
381
+ // No population so no need to scrub
414
382
 
415
- _.each(results, function(result) {
416
- _.each(result.snapshots, function(snapshot) {
383
+ query.exec(function(err, result) {
417
384
 
418
- var isManagedServices = snapshot.managedServices;
419
- var isSubmitted = snapshot.submittedOn;
420
- var isNotReviewed = !snapshot.reviewedOn;
385
+ if (err) { return cb(err, null); }
421
386
 
422
- if(isManagedServices && isSubmitted && isNotReviewed) {
423
- snapshots.push({
424
- organization: result.organization.name,
425
- snapshot: snapshot
426
- });
427
- }
387
+ let snapshots = _.pluck(result || [], 'snapshots');
428
388
 
429
- });
430
- });
389
+ snapshots = _.flatten(snapshots);
431
390
 
432
- if (err) { return cb(err, null); }
433
- return cb(null, snapshots);
391
+ snapshots = _.filter(snapshots, function(snapshot) {
434
392
 
435
- });
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;
436
396
 
437
- };
397
+ return bool;
438
398
 
439
- Financials.statics.getToSend = function getToSend(uuid, cb) {
399
+ });
440
400
 
441
- var self = this;
401
+ return cb(null, _.pluck(snapshots, 'uuid'));
442
402
 
443
- var query = self.findOne({
444
- 'snapshots.uuid': uuid
445
403
  });
446
404
 
447
- query.populate('organization', 'name logoUrl');
448
- query.populate('customer', 'name logoUrl customer.totemUrl');
449
-
450
- query.exec(cb);
451
-
452
405
  };
453
406
 
454
407
  Financials.statics.removeCustomerFinancials = function removeCustomerFinancials(customerId, cb) {
@@ -456,7 +409,9 @@ module.exports = function(mongoose, config) {
456
409
  // this is only used to wipe out financials created by the google sheet import process
457
410
  // we do NOT want to delete any financials submitted via forms generated directly from the app
458
411
 
459
- var self = this;
412
+ let self = this;
413
+
414
+ // No population so no need to scrub
460
415
 
461
416
  self
462
417
  .update(
@@ -469,6 +424,7 @@ module.exports = function(mongoose, config) {
469
424
 
470
425
  Financials.statics.upsert = function upsert(financials, cb) {
471
426
 
427
+ if (!cb) { throw new Error('cb is required'); }
472
428
  if (!financials) { return cb(new Error('financials is required'), null); }
473
429
 
474
430
  // Required for mixed types
@@ -485,6 +441,8 @@ module.exports = function(mongoose, config) {
485
441
  financials.markModified('investingActivities.breakdown');
486
442
  financials.markModified('financingActivities.breakdown');
487
443
 
444
+ // No population so no need to scrub
445
+
488
446
  financials.save(cb);
489
447
 
490
448
  };
@@ -505,24 +463,17 @@ module.exports = function(mongoose, config) {
505
463
 
506
464
  if(!snapshot) return;
507
465
 
508
- var isManagedServices = snapshot.managedServices;
509
- var isSubmitted = snapshot.submittedOn;
510
- var isReviewed = snapshot.reviewedOn;
511
- var isRejected = snapshot.rejection;
512
-
513
466
  // no uuid means the data was captured from the google sheet
514
- if((!snapshot.uuid) || (!isManagedServices && isSubmitted) || (isManagedServices && isReviewed)) {
467
+ if((!snapshot.uuid) || (!snapshot.managedServices && snapshot.submittedOn) || (snapshot.managedServices && snapshot.reviewedOn)) {
515
468
  snapshot.status = 'Completed';
516
469
  snapshot.action = null;
517
470
  }
518
471
 
519
- else if(snapshot.notifications.company && snapshot.notifications.company.initial && snapshot.notifications.company.initial.sendOn) {
520
-
521
- var latestReminder = _.max(snapshot.notifications.company.reminders, function(r) { return new Date(r.sendOn); });
522
-
523
- var isScheduled = snapshot.notifications.company.initial.sendOn && moment().isBefore(moment(snapshot.notifications.company.initial.sendOn));
524
- var isOverdue = latestReminder.sendOn && moment().subtract(14, 'd').isAfter(moment(latestReminder.sendOn));
472
+ else if(snapshot.notifications.company.initial.sendOn) {
525
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
+
526
477
  if(isScheduled) {
527
478
  snapshot.status = 'Scheduled';
528
479
  snapshot.action = null;
@@ -535,10 +486,9 @@ module.exports = function(mongoose, config) {
535
486
 
536
487
  else {
537
488
  snapshot.status = 'In Progress';
538
- if(isManagedServices && isSubmitted && !isRejected) snapshot.action = 'Review';
539
- else if(isManagedServices && isSubmitted && isRejected) snapshot.action = 'Rejected';
540
- else if(latestReminder.sentOn) snapshot.action = latestReminder.status;
541
- 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;
542
492
  }
543
493
 
544
494
  }
@@ -554,22 +504,11 @@ module.exports = function(mongoose, config) {
554
504
 
555
505
  });
556
506
 
557
- Financials.post('init', function(doc, next) {
558
-
559
- return next();
560
-
561
- });
562
-
563
- Financials.post('remove', function(doc) {
564
- // todo
565
- });
566
-
567
507
  ///////////////////////////////////////////////////////////////////////////////////////
568
508
  // CONFIG
569
509
  ///////////////////////////////////////////////////////////////////////////////////////
570
510
 
571
511
  Financials.set('toJSON', { virtuals: true });
572
- Financials.set('usePushEach', true);
573
512
  Financials.set('autoIndex', false);
574
513
 
575
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 **********************/
@@ -75,9 +71,16 @@ module.exports = function(mongoose, config) {
75
71
  ///////////////////////////////////////
76
72
 
77
73
  Fund.statics.findBySlugs = function findBySlugs(slugs, cb) {
78
- this
74
+
75
+ const self = this;
76
+
77
+ if (!cb) { throw new Error('cb is required'); }
78
+ if (!slugs) { return cb(new Error('slug must be provided'), null); }
79
+
80
+ self
79
81
  .find({ 'slug': { $in : slugs }})
80
82
  .exec(cb);
83
+
81
84
  };
82
85
 
83
86
  Fund.statics.getById = function getById(id, cb) {
@@ -152,7 +155,8 @@ module.exports = function(mongoose, config) {
152
155
  if (!query) return cb(null, []);
153
156
 
154
157
  var conditions = {
155
- 'name': new RegExp(query, "i")
158
+ 'name': new RegExp(query.query, "i"),
159
+ 'deleted': {$ne: true}
156
160
  };
157
161
 
158
162
  this
@@ -171,31 +175,7 @@ module.exports = function(mongoose, config) {
171
175
 
172
176
  };
173
177
 
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
178
  Fund.set('autoIndex', false);
198
- Fund.set('usePushEach', true);
199
179
  Fund.on('index', function(err) { console.log('error building fund indexes: ' + err); });
200
180
 
201
181
  mongoose.model('Fund', Fund);