@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/.npmignore +14 -0
- package/helpers.js +89 -0
- package/index.js +0 -1
- package/lib/Account.js +125 -79
- package/lib/Activity.js +0 -2
- package/lib/CalendarEvent.js +1 -7
- package/lib/CapTable.js +0 -1
- package/lib/Deal.js +215 -151
- package/lib/Document.js +57 -56
- package/lib/Financials.js +115 -172
- package/lib/Flag.js +37 -14
- package/lib/Fund.js +6 -33
- package/lib/Interaction.js +79 -32
- package/lib/Investment.js +4 -10
- package/lib/LimitedPartner.js +303 -634
- package/lib/List.js +105 -147
- package/lib/Message.js +100 -51
- package/lib/News.js +1 -53
- package/lib/Note.js +60 -66
- package/lib/Organization.js +470 -645
- package/lib/Person.js +342 -650
- package/lib/Round.js +191 -134
- package/lib/Snapshot.js +3 -5
- package/lib/Webhook.js +1 -4
- package/package-lock.json +1927 -0
- package/package.json +2 -3
- package/test/Account.js +53 -38
- package/test/Deal.js +14 -30
- package/test/Document.js +51 -50
- package/test/Financials.js +5 -3
- package/test/Flag.js +18 -14
- package/test/Interaction.js +1 -31
- package/test/Investment.js +2 -3
- package/test/LimitedPartner.js +399 -554
- package/test/List.js +24 -29
- package/test/Message.js +7 -46
- package/test/News.js +12 -29
- package/test/Note.js +23 -22
- package/test/Organization.js +33 -307
- package/test/Person.js +6 -253
- package/test/Round.js +11 -11
- package/lib/Sync.js +0 -48
package/lib/Round.js
CHANGED
|
@@ -16,17 +16,15 @@
|
|
|
16
16
|
//
|
|
17
17
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
19
|
module.exports = function(mongoose, config) {
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
let Schema = mongoose.Schema;
|
|
22
|
+
let utils = require('@dhyasama/ffvc-utilities');
|
|
23
|
+
let async = require('async');
|
|
24
|
+
let _ = require('underscore');
|
|
25
|
+
let helpers = require('../helpers');
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
let Round = new Schema({
|
|
30
28
|
|
|
31
29
|
organization: { type: Schema.ObjectId, ref: 'Organization', required: true, index: true },
|
|
32
30
|
|
|
@@ -150,7 +148,6 @@ module.exports = function(mongoose, config) {
|
|
|
150
148
|
// construct the org
|
|
151
149
|
var org = {
|
|
152
150
|
_id: rounds[0].organization._id,
|
|
153
|
-
slug: rounds[0].organization.slug,
|
|
154
151
|
name: rounds[0].organization.name,
|
|
155
152
|
logoUrl: rounds[0].organization.logoUrl,
|
|
156
153
|
description: rounds[0].organization.description,
|
|
@@ -178,7 +175,7 @@ module.exports = function(mongoose, config) {
|
|
|
178
175
|
|
|
179
176
|
};
|
|
180
177
|
|
|
181
|
-
var checkForUnpopulatedData = function checkForUnpopulatedData(rounds, fnName
|
|
178
|
+
var checkForUnpopulatedData = function checkForUnpopulatedData(rounds, fnName) {
|
|
182
179
|
|
|
183
180
|
// If one of these things isn't populated, that means we have bad data
|
|
184
181
|
// Fuck shit up so it gets taken care of
|
|
@@ -406,52 +403,55 @@ module.exports = function(mongoose, config) {
|
|
|
406
403
|
// Statics operate on the entire collection
|
|
407
404
|
//////////////////////////////////////////////////////
|
|
408
405
|
|
|
409
|
-
Round.statics.
|
|
406
|
+
Round.statics.getByOrg = function getByOrg(orgId, options, cb) {
|
|
410
407
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
self
|
|
414
|
-
.find({ 'vehicles.fund': fundId })
|
|
415
|
-
.exec(cb);
|
|
408
|
+
// Gets all the rounds an org has raised
|
|
416
409
|
|
|
417
|
-
|
|
410
|
+
const self = this;
|
|
418
411
|
|
|
419
|
-
|
|
412
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
413
|
+
if (!orgId) { throw new Error('orgId is required'); }
|
|
414
|
+
if (!mongoose.Types.ObjectId.isValid(orgId)) { return cb(new Error('orgId is not a valid ObjectId'), null); }
|
|
415
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
420
416
|
|
|
421
|
-
|
|
417
|
+
options = helpers.getDefaultOptions(options);
|
|
422
418
|
|
|
423
|
-
|
|
419
|
+
if (!options.isWorkerProcess) {
|
|
420
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
421
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
422
|
+
}
|
|
424
423
|
|
|
425
|
-
|
|
424
|
+
let query = self.find({
|
|
426
425
|
'deleted': { $ne: true },
|
|
427
426
|
'organization': orgId
|
|
428
427
|
});
|
|
428
|
+
|
|
429
429
|
query.populate('organization', 'name logoUrl website websiteAliases');
|
|
430
430
|
query.populate('people.person', 'name avatarUrl title');
|
|
431
431
|
query.populate('vehicles.fund', 'name shortName');
|
|
432
432
|
|
|
433
|
-
if (
|
|
433
|
+
if (options.isWorkerProcess) {
|
|
434
434
|
query.populate('vehicles.investments');
|
|
435
435
|
}
|
|
436
436
|
else {
|
|
437
437
|
query.populate({
|
|
438
438
|
path: 'vehicles.investments',
|
|
439
|
-
match: { customer:
|
|
439
|
+
match: { customer: options.CUSTOMER_ID }
|
|
440
440
|
});
|
|
441
441
|
}
|
|
442
442
|
|
|
443
443
|
query.exec(function(err, rounds) {
|
|
444
444
|
|
|
445
|
-
if (err) return cb(err, null);
|
|
446
|
-
if (!rounds || rounds.length
|
|
445
|
+
if (err) { return cb(err, null); }
|
|
446
|
+
if (!rounds || rounds.length === 0) { return cb(null, []); }
|
|
447
447
|
|
|
448
|
-
|
|
449
|
-
if (error) return cb(error, null);
|
|
448
|
+
let error = checkForUnpopulatedData(rounds, 'Round.getByOrg');
|
|
449
|
+
if (error) { return cb(error, null); }
|
|
450
450
|
|
|
451
451
|
// reverse chronological
|
|
452
452
|
rounds = _.sortBy(rounds, function(r) {
|
|
453
453
|
|
|
454
|
-
|
|
454
|
+
let date = r.closingDate;
|
|
455
455
|
|
|
456
456
|
// use investment date in absence of closing date
|
|
457
457
|
if (!date && r.vehicles.length && r.vehicles[0].investments.length) {
|
|
@@ -468,40 +468,52 @@ module.exports = function(mongoose, config) {
|
|
|
468
468
|
|
|
469
469
|
};
|
|
470
470
|
|
|
471
|
-
Round.statics.getByOrgs = function getByOrg(orgIds, cb) {
|
|
471
|
+
Round.statics.getByOrgs = function getByOrg(orgIds, options, cb) {
|
|
472
472
|
|
|
473
|
-
|
|
473
|
+
const self = this;
|
|
474
|
+
|
|
475
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
476
|
+
if (!orgIds) { throw new Error('orgIds is required'); }
|
|
477
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
478
|
+
|
|
479
|
+
options = helpers.getDefaultOptions(options);
|
|
480
|
+
|
|
481
|
+
if (!options.isWorkerProcess) {
|
|
482
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
483
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
484
|
+
}
|
|
474
485
|
|
|
475
|
-
|
|
486
|
+
let query = self.find({
|
|
476
487
|
'deleted': { $ne: true },
|
|
477
488
|
'organization': { $in: orgIds }
|
|
478
489
|
});
|
|
490
|
+
|
|
479
491
|
query.populate('organization', 'name logoUrl website websiteAliases');
|
|
480
492
|
query.populate('people.person', 'name avatarUrl');
|
|
481
493
|
query.populate('vehicles.fund');
|
|
482
494
|
|
|
483
|
-
if (
|
|
495
|
+
if (options.isWorkerProcess) {
|
|
484
496
|
query.populate('vehicles.investments');
|
|
485
497
|
}
|
|
486
498
|
else {
|
|
487
499
|
query.populate({
|
|
488
500
|
path: 'vehicles.investments',
|
|
489
|
-
match: { customer:
|
|
501
|
+
match: { customer: options.CUSTOMER_ID }
|
|
490
502
|
});
|
|
491
503
|
}
|
|
492
504
|
|
|
493
505
|
query.exec(function(err, rounds) {
|
|
494
506
|
|
|
495
507
|
if (err) return cb(err, null);
|
|
496
|
-
if (!rounds || rounds.length
|
|
508
|
+
if (!rounds || rounds.length === 0) return cb(null, []);
|
|
497
509
|
|
|
498
|
-
|
|
510
|
+
let error = checkForUnpopulatedData(rounds, 'Round.getByOrgs');
|
|
499
511
|
if (error) return cb(error, null);
|
|
500
512
|
|
|
501
513
|
// reverse chronological
|
|
502
514
|
rounds = _.sortBy(rounds, function(r) {
|
|
503
515
|
|
|
504
|
-
|
|
516
|
+
let date = r.closingDate;
|
|
505
517
|
|
|
506
518
|
// use investment date in absence of closing date
|
|
507
519
|
if (!date && r.vehicles.length && r.vehicles[0].investments.length) {
|
|
@@ -518,21 +530,33 @@ module.exports = function(mongoose, config) {
|
|
|
518
530
|
|
|
519
531
|
};
|
|
520
532
|
|
|
521
|
-
Round.statics.getFundInvestments = function getFundInvestments(fundId, cb) {
|
|
533
|
+
Round.statics.getFundInvestments = function getFundInvestments(fundId, options, cb) {
|
|
522
534
|
|
|
523
|
-
|
|
535
|
+
const self = this;
|
|
536
|
+
|
|
537
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
538
|
+
if (!fundId) { throw new Error('fundId is required'); }
|
|
539
|
+
if (!mongoose.Types.ObjectId.isValid(fundId)) { return cb(new Error('fundId is not a valid ObjectId'), null); }
|
|
540
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
524
541
|
|
|
525
|
-
|
|
542
|
+
options = helpers.getDefaultOptions(options);
|
|
543
|
+
|
|
544
|
+
if (!options.isWorkerProcess) {
|
|
545
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
546
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
let query = self.find({ 'vehicles.fund': fundId });
|
|
526
550
|
query.select('organization roundName vehicles');
|
|
527
551
|
query.populate('organization', 'name logoUrl website websiteAliases');
|
|
528
552
|
|
|
529
|
-
if (
|
|
553
|
+
if (options.isWorkerProcess) {
|
|
530
554
|
query.populate('vehicles.investments');
|
|
531
555
|
}
|
|
532
556
|
else {
|
|
533
557
|
query.populate({
|
|
534
558
|
path: 'vehicles.investments',
|
|
535
|
-
match: { customer:
|
|
559
|
+
match: { customer: options.CUSTOMER_ID }
|
|
536
560
|
});
|
|
537
561
|
}
|
|
538
562
|
|
|
@@ -541,11 +565,11 @@ module.exports = function(mongoose, config) {
|
|
|
541
565
|
if (err) return cb(err, null);
|
|
542
566
|
if (!rounds) return cb(null, []);
|
|
543
567
|
|
|
544
|
-
|
|
568
|
+
let fundInvestments = [];
|
|
545
569
|
|
|
546
570
|
_.each(rounds, function(round) {
|
|
547
571
|
_.each(round.vehicles, function(vehicle) {
|
|
548
|
-
if(vehicle.fund
|
|
572
|
+
if(vehicle.fund === fundId) {
|
|
549
573
|
_.each(vehicle.investments, function(investment) {
|
|
550
574
|
investment.organization = round.organization;
|
|
551
575
|
investment.roundName = round.roundName;
|
|
@@ -563,72 +587,89 @@ module.exports = function(mongoose, config) {
|
|
|
563
587
|
|
|
564
588
|
Round.statics.getFundPerformance = function getFundPerformance(fundId, cb) {
|
|
565
589
|
|
|
566
|
-
|
|
590
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
591
|
+
if (!fundId) { throw new Error('fundId is required'); }
|
|
592
|
+
if (!mongoose.Types.ObjectId.isValid(fundId)) { return cb(new Error('fundId is not a valid ObjectId'), null); }
|
|
567
593
|
|
|
568
|
-
self
|
|
569
|
-
.find({ 'vehicles.fund': fundId })
|
|
570
|
-
.exec(function(err, rounds) {
|
|
594
|
+
const self = this;
|
|
571
595
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
}, 0);
|
|
589
|
-
|
|
590
|
-
var totalRealized = _.reduce(rounds, function(memo, round) {
|
|
591
|
-
var roundValue = _.reduce(round.vehicles, function(memo, vehicle) { return memo + vehicle.realized; }, 0);
|
|
592
|
-
return memo + roundValue;
|
|
593
|
-
}, 0);
|
|
594
|
-
|
|
595
|
-
return cb(null, {
|
|
596
|
-
cost: totalFundCost,
|
|
597
|
-
unrealized: totalUnrealized,
|
|
598
|
-
realized: totalRealized,
|
|
599
|
-
value: totalUnrealized + totalRealized,
|
|
600
|
-
multiple: totalFundCost > 0 ? (totalUnrealized + totalRealized) / totalFundCost : 0
|
|
601
|
-
});
|
|
596
|
+
let query = self.find({ 'vehicles.fund': fundId });
|
|
597
|
+
|
|
598
|
+
query.exec(function(err, rounds) {
|
|
599
|
+
|
|
600
|
+
if (err) return cb(err, null);
|
|
601
|
+
else if (!rounds) return cb(null, null);
|
|
602
|
+
else if(rounds.length === 0) return cb(null, []);
|
|
603
|
+
|
|
604
|
+
rounds = filterVehicles(rounds, [fundId]);
|
|
605
|
+
|
|
606
|
+
// we now have all the rounds the fund has participated in with other fund information removed from each round
|
|
607
|
+
|
|
608
|
+
let totalFundCost = _.reduce(rounds, function(memo, round) {
|
|
609
|
+
let roundCost = _.reduce(round.vehicles, function(memo, vehicle) { return memo + vehicle.cost; }, 0);
|
|
610
|
+
return memo + roundCost;
|
|
611
|
+
}, 0);
|
|
602
612
|
|
|
613
|
+
let totalUnrealized = _.reduce(rounds, function(memo, round) {
|
|
614
|
+
let roundValue = _.reduce(round.vehicles, function(memo, vehicle) { return memo + vehicle.fairValue; }, 0);
|
|
615
|
+
return memo + roundValue;
|
|
616
|
+
}, 0);
|
|
617
|
+
|
|
618
|
+
let totalRealized = _.reduce(rounds, function(memo, round) {
|
|
619
|
+
let roundValue = _.reduce(round.vehicles, function(memo, vehicle) { return memo + vehicle.realized; }, 0);
|
|
620
|
+
return memo + roundValue;
|
|
621
|
+
}, 0);
|
|
622
|
+
|
|
623
|
+
return cb(null, {
|
|
624
|
+
cost: totalFundCost,
|
|
625
|
+
unrealized: totalUnrealized,
|
|
626
|
+
realized: totalRealized,
|
|
627
|
+
value: totalUnrealized + totalRealized,
|
|
628
|
+
multiple: totalFundCost > 0 ? (totalUnrealized + totalRealized) / totalFundCost : 0
|
|
603
629
|
});
|
|
604
630
|
|
|
631
|
+
});
|
|
632
|
+
|
|
605
633
|
};
|
|
606
634
|
|
|
607
|
-
Round.statics.getPortfolioByFund = function getPortfolioByFund(fundId, cb) {
|
|
635
|
+
Round.statics.getPortfolioByFund = function getPortfolioByFund(fundId, options, cb) {
|
|
608
636
|
|
|
609
|
-
|
|
637
|
+
const self = this;
|
|
638
|
+
|
|
639
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
640
|
+
if (!fundId) { throw new Error('fundId is required'); }
|
|
641
|
+
if (!mongoose.Types.ObjectId.isValid(fundId)) { return cb(new Error('fundId is not a valid ObjectId'), null); }
|
|
642
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
643
|
+
|
|
644
|
+
options = helpers.getDefaultOptions(options);
|
|
645
|
+
|
|
646
|
+
if (!options.isWorkerProcess) {
|
|
647
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
648
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
let query = self.find({ 'vehicles.fund': fundId });
|
|
610
652
|
|
|
611
|
-
var query = self.find({ 'vehicles.fund': fundId });
|
|
612
653
|
query.select('organization vehicles preMoneyValuation');
|
|
613
|
-
query.populate('organization', 'name
|
|
654
|
+
query.populate('organization', 'name logoUrl description contact filters status ipo closed acquired operating website websiteAliases');
|
|
614
655
|
query.populate('vehicles.fund');
|
|
615
656
|
|
|
616
|
-
if (
|
|
657
|
+
if (options.isWorkerProcess) {
|
|
617
658
|
query.populate('vehicles.investments');
|
|
618
659
|
}
|
|
619
660
|
else {
|
|
620
661
|
query.populate({
|
|
621
662
|
path: 'vehicles.investments',
|
|
622
|
-
match: { customer:
|
|
663
|
+
match: { customer: options.CUSTOMER_ID }
|
|
623
664
|
});
|
|
624
665
|
}
|
|
625
666
|
|
|
626
667
|
query.exec(function(err, rounds) {
|
|
627
668
|
|
|
628
669
|
if (err) return cb(err, null);
|
|
629
|
-
if (!rounds || rounds.length
|
|
670
|
+
if (!rounds || rounds.length === 0) return cb(null, []);
|
|
630
671
|
|
|
631
|
-
|
|
672
|
+
let error = checkForUnpopulatedData(rounds, 'Round.getPortfolioByFund');
|
|
632
673
|
if (error) return cb(error, null);
|
|
633
674
|
|
|
634
675
|
return cb(null, buildPortfolio(rounds, [fundId]));
|
|
@@ -637,16 +678,28 @@ module.exports = function(mongoose, config) {
|
|
|
637
678
|
|
|
638
679
|
};
|
|
639
680
|
|
|
640
|
-
Round.statics.getPortfolioByFunds = function getPortfolioByFunds(fundIds, cb) {
|
|
681
|
+
Round.statics.getPortfolioByFunds = function getPortfolioByFunds(fundIds, options, cb) {
|
|
641
682
|
|
|
642
683
|
// Returns a list of orgs that have rounds participated in by the given fund ids
|
|
643
684
|
// Note retrieving multiple funds does not calculate fund stats. Use getPortfolioByFund for that.
|
|
644
685
|
|
|
645
|
-
|
|
686
|
+
const self = this;
|
|
687
|
+
|
|
688
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
689
|
+
if (!fundIds) { throw new Error('fundIds is required'); }
|
|
690
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
691
|
+
|
|
692
|
+
options = helpers.getDefaultOptions(options);
|
|
693
|
+
|
|
694
|
+
if (!options.isWorkerProcess) {
|
|
695
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
696
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
let query = self.find({ 'vehicles.fund': { $in: fundIds } });
|
|
646
700
|
|
|
647
|
-
var query = self.find({ 'vehicles.fund': { $in: fundIds } });
|
|
648
701
|
query.select('organization vehicles preMoneyValuation');
|
|
649
|
-
query.populate('organization', 'name
|
|
702
|
+
query.populate('organization', 'name logoUrl description contact chairs filters status ipo closed acquired operating website websiteAliases');
|
|
650
703
|
query.deepPopulate([
|
|
651
704
|
'organization.chairs.first',
|
|
652
705
|
'organization.chairs.second',
|
|
@@ -658,22 +711,22 @@ module.exports = function(mongoose, config) {
|
|
|
658
711
|
});
|
|
659
712
|
query.populate('vehicles.fund');
|
|
660
713
|
|
|
661
|
-
if (
|
|
714
|
+
if (options.isWorkerProcess) {
|
|
662
715
|
query.populate('vehicles.investments');
|
|
663
716
|
}
|
|
664
717
|
else {
|
|
665
718
|
query.populate({
|
|
666
719
|
path: 'vehicles.investments',
|
|
667
|
-
match: { customer:
|
|
720
|
+
match: { customer: options.CUSTOMER_ID }
|
|
668
721
|
});
|
|
669
722
|
}
|
|
670
723
|
|
|
671
724
|
query.exec(function(err, rounds) {
|
|
672
725
|
|
|
673
726
|
if (err) return cb(err, null);
|
|
674
|
-
if (!rounds || rounds.length
|
|
727
|
+
if (!rounds || rounds.length === 0) return cb(null, []);
|
|
675
728
|
|
|
676
|
-
|
|
729
|
+
let error = checkForUnpopulatedData(rounds, 'Round.getPortfolioByFunds');
|
|
677
730
|
if (error) return cb(error, null);
|
|
678
731
|
|
|
679
732
|
return cb(null, buildPortfolio(rounds, fundIds));
|
|
@@ -682,32 +735,37 @@ module.exports = function(mongoose, config) {
|
|
|
682
735
|
|
|
683
736
|
};
|
|
684
737
|
|
|
685
|
-
Round.statics.getPortfolioByPerson = function getPortfolioByPerson(personId, cb) {
|
|
738
|
+
Round.statics.getPortfolioByPerson = function getPortfolioByPerson(personId, options, cb) {
|
|
686
739
|
|
|
687
740
|
// Returns a list of orgs that have rounds participated in by the given person id
|
|
688
741
|
|
|
689
|
-
|
|
742
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
743
|
+
if (!personId) { throw new Error('personId is required'); }
|
|
744
|
+
if (!mongoose.Types.ObjectId.isValid(personId)) { return cb(new Error('personId is not a valid ObjectId'), null); }
|
|
690
745
|
|
|
691
|
-
self
|
|
692
|
-
.find({ 'people.person': personId })
|
|
693
|
-
.select('organization')
|
|
694
|
-
.populate('organization', 'name logoUrl description website websiteAliases')
|
|
695
|
-
.exec(function(err, rounds) {
|
|
746
|
+
const self = this;
|
|
696
747
|
|
|
697
|
-
|
|
698
|
-
if (!rounds || rounds.length == 0) return cb(null, []);
|
|
748
|
+
let query = self.find({ 'people.person': personId });
|
|
699
749
|
|
|
700
|
-
|
|
701
|
-
|
|
750
|
+
query.select('organization');
|
|
751
|
+
query.populate('organization', 'name logoUrl description website websiteAliases');
|
|
702
752
|
|
|
703
|
-
|
|
704
|
-
var portfolio = _.pluck(rounds, 'organization');
|
|
705
|
-
portfolio = _.uniq(portfolio, function(org) { return org.name; });
|
|
706
|
-
portfolio = _.sortBy(portfolio, 'name');
|
|
753
|
+
query.exec(function(err, rounds) {
|
|
707
754
|
|
|
708
|
-
|
|
755
|
+
if (err) return cb(err, null);
|
|
756
|
+
if (!rounds || rounds.length === 0) return cb(null, []);
|
|
709
757
|
|
|
710
|
-
|
|
758
|
+
let error = checkForUnpopulatedData(rounds, 'Round.getPortfolioByPerson');
|
|
759
|
+
if (error) return cb(error, null);
|
|
760
|
+
|
|
761
|
+
// Return a list of orgs, not a list of rounds
|
|
762
|
+
let portfolio = _.pluck(rounds, 'organization');
|
|
763
|
+
portfolio = _.uniq(portfolio, function(org) { return org.name; });
|
|
764
|
+
portfolio = _.sortBy(portfolio, 'name');
|
|
765
|
+
|
|
766
|
+
return cb(null, portfolio);
|
|
767
|
+
|
|
768
|
+
});
|
|
711
769
|
|
|
712
770
|
};
|
|
713
771
|
|
|
@@ -722,16 +780,20 @@ module.exports = function(mongoose, config) {
|
|
|
722
780
|
// removed, call update to remove the investments from rounds, retrieve the updated rounds and save them which will
|
|
723
781
|
// trigger the pre-save hook and update the cost.
|
|
724
782
|
|
|
725
|
-
|
|
783
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
784
|
+
if (!investmentId) { throw new Error('investmentId is required'); }
|
|
785
|
+
if (!mongoose.Types.ObjectId.isValid(investmentId)) { return cb(new Error('investmentId is not a valid ObjectId'), null); }
|
|
786
|
+
|
|
787
|
+
const self = this;
|
|
726
788
|
|
|
727
|
-
|
|
728
|
-
|
|
789
|
+
let getRounds = function getRounds(callback) {
|
|
790
|
+
let query = self.find({ 'vehicles.investments': investmentId });
|
|
729
791
|
query.select('_id');
|
|
730
792
|
query.exec(callback);
|
|
731
793
|
};
|
|
732
794
|
|
|
733
|
-
|
|
734
|
-
|
|
795
|
+
let updateRounds = function updateRounds(previous, callback) {
|
|
796
|
+
let query = self.update(
|
|
735
797
|
{ 'vehicles.investments': investmentId },
|
|
736
798
|
{ $pull : { 'vehicles.$.investments': investmentId } },
|
|
737
799
|
{ multi : true }
|
|
@@ -739,10 +801,10 @@ module.exports = function(mongoose, config) {
|
|
|
739
801
|
query.exec(callback);
|
|
740
802
|
};
|
|
741
803
|
|
|
742
|
-
|
|
804
|
+
let updateCost = function updateCost(previous, callback) {
|
|
743
805
|
|
|
744
|
-
|
|
745
|
-
|
|
806
|
+
let ids = _.pluck(previous, '_id');
|
|
807
|
+
let query = self.find({_id: { $in: ids }});
|
|
746
808
|
|
|
747
809
|
query.exec(function (err, docs) {
|
|
748
810
|
async.map(docs, function (doc, saveCallback) {
|
|
@@ -764,7 +826,7 @@ module.exports = function(mongoose, config) {
|
|
|
764
826
|
|
|
765
827
|
Round.statics.removePerson = function(roundId, personId, cb) {
|
|
766
828
|
|
|
767
|
-
|
|
829
|
+
const self = this;
|
|
768
830
|
|
|
769
831
|
self
|
|
770
832
|
.findOneAndUpdate(
|
|
@@ -778,7 +840,7 @@ module.exports = function(mongoose, config) {
|
|
|
778
840
|
|
|
779
841
|
Round.statics.removeVehicle = function(roundId, fundId, cb) {
|
|
780
842
|
|
|
781
|
-
|
|
843
|
+
const self = this;
|
|
782
844
|
|
|
783
845
|
self
|
|
784
846
|
.findOneAndUpdate(
|
|
@@ -794,7 +856,7 @@ module.exports = function(mongoose, config) {
|
|
|
794
856
|
|
|
795
857
|
if (!round) { return cb(new Error('round is required'), null); }
|
|
796
858
|
|
|
797
|
-
|
|
859
|
+
const compute = function compute(doc) {
|
|
798
860
|
|
|
799
861
|
// compute for each vehicle
|
|
800
862
|
|
|
@@ -851,8 +913,6 @@ module.exports = function(mongoose, config) {
|
|
|
851
913
|
|
|
852
914
|
};
|
|
853
915
|
|
|
854
|
-
|
|
855
|
-
|
|
856
916
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
857
917
|
// HOOKS
|
|
858
918
|
// Pre-save: fired on every document before it is saved
|
|
@@ -862,9 +922,7 @@ module.exports = function(mongoose, config) {
|
|
|
862
922
|
|
|
863
923
|
Round.post('init', function(doc, next) {
|
|
864
924
|
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
if (CUSTOMER_ID == 'GLOBAL_PROCESS') return next();
|
|
925
|
+
if (!doc || !doc.vehicles) { return next(); }
|
|
868
926
|
|
|
869
927
|
// note participating people are public as there is no investment, i.e., private, data attached to them
|
|
870
928
|
|
|
@@ -876,22 +934,22 @@ module.exports = function(mongoose, config) {
|
|
|
876
934
|
|
|
877
935
|
// participating vehicles are public
|
|
878
936
|
// merge private data that was matched for customer
|
|
879
|
-
|
|
937
|
+
|
|
880
938
|
doc.vehicles = _.filter(doc.vehicles, function(vehicle) {
|
|
881
939
|
return vehicle.investments.length > 0;
|
|
882
940
|
});
|
|
883
941
|
|
|
884
|
-
|
|
885
|
-
|
|
942
|
+
let allInvestments = _.flatten(_.pluck(doc.vehicles, 'investments'));
|
|
943
|
+
let mostRecentInvestment = _.max(allInvestments, function(investment) { return investment.investmentDate; });
|
|
886
944
|
|
|
887
945
|
// if we have private data, use it rather than the public data
|
|
888
946
|
if (mostRecentInvestment) {
|
|
889
|
-
if (mostRecentInvestment.preMoneyValuation) doc.preMoneyValuation = mostRecentInvestment.preMoneyValuation;
|
|
890
|
-
if (mostRecentInvestment.dollarsRaised) doc.dollarsRaised = mostRecentInvestment.dollarsRaised;
|
|
891
|
-
if (mostRecentInvestment.closingDate) doc.closingDate = mostRecentInvestment.closingDate;
|
|
947
|
+
if (mostRecentInvestment.preMoneyValuation) { doc.preMoneyValuation = mostRecentInvestment.preMoneyValuation; }
|
|
948
|
+
if (mostRecentInvestment.dollarsRaised) { doc.dollarsRaised = mostRecentInvestment.dollarsRaised; }
|
|
949
|
+
if (mostRecentInvestment.closingDate) { doc.closingDate = mostRecentInvestment.closingDate; }
|
|
892
950
|
}
|
|
893
951
|
|
|
894
|
-
|
|
952
|
+
next();
|
|
895
953
|
|
|
896
954
|
});
|
|
897
955
|
|
|
@@ -900,7 +958,6 @@ module.exports = function(mongoose, config) {
|
|
|
900
958
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
901
959
|
|
|
902
960
|
Round.set('toJSON', { virtuals: true });
|
|
903
|
-
Round.set('usePushEach', true);
|
|
904
961
|
Round.set('autoIndex', false);
|
|
905
962
|
|
|
906
963
|
Round.index({ organization: 1, roundName: 1 }, { unique: true, partialFilterExpression : { type :"string" } });
|
package/lib/Snapshot.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
module.exports = function(mongoose, config) {
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
let Schema = mongoose.Schema;
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
let Snapshot = new Schema({
|
|
8
8
|
|
|
9
9
|
createdOn: { type: Date, default: Date.now },
|
|
10
10
|
createdBy: { type: String, required: true, trim: true },
|
|
@@ -15,7 +15,7 @@ module.exports = function(mongoose, config) {
|
|
|
15
15
|
|
|
16
16
|
Snapshot.statics.getByDocId = function getByDocId(docId, cb) {
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
const self = this;
|
|
19
19
|
|
|
20
20
|
self
|
|
21
21
|
.find({ 'doc._id': docId })
|
|
@@ -28,8 +28,6 @@ module.exports = function(mongoose, config) {
|
|
|
28
28
|
snapshot.save(cb);
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
Snapshot.set('usePushEach', true);
|
|
32
|
-
|
|
33
31
|
mongoose.model('Snapshot', Snapshot, '_Snapshots');
|
|
34
32
|
|
|
35
33
|
};
|
package/lib/Webhook.js
CHANGED
|
@@ -4,9 +4,7 @@ module.exports = function(mongoose, config) {
|
|
|
4
4
|
|
|
5
5
|
var
|
|
6
6
|
|
|
7
|
-
Schema = mongoose.Schema
|
|
8
|
-
env = process.env.NODE_ENV || 'development',
|
|
9
|
-
_ = require('underscore');
|
|
7
|
+
Schema = mongoose.Schema;
|
|
10
8
|
|
|
11
9
|
var Webhook = new Schema({
|
|
12
10
|
|
|
@@ -24,7 +22,6 @@ module.exports = function(mongoose, config) {
|
|
|
24
22
|
};
|
|
25
23
|
|
|
26
24
|
Webhook.set('autoIndex', false);
|
|
27
|
-
Webhook.set('usePushEach', true);
|
|
28
25
|
|
|
29
26
|
mongoose.model('Webhook', Webhook);
|
|
30
27
|
|