@dhyasama/totem-models 12.3.0 → 12.4.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/Account.js +120 -109
- package/lib/Activity.js +23 -13
- package/lib/ApiKey.js +24 -21
- package/lib/CalendarEvent.js +100 -61
- package/lib/CapTable.js +148 -107
- package/lib/Deal.js +409 -364
- package/lib/DiffbotArticle.js +21 -15
- package/lib/DiffbotOrganization.js +21 -15
- package/lib/Document.js +60 -44
- package/lib/Event.js +38 -21
- package/lib/EventAttendee.js +29 -17
- package/lib/Financials.js +400 -367
- package/lib/FinancialsAnalysis.js +49 -38
- package/lib/Flag.js +42 -35
- package/lib/Folder.js +33 -20
- package/lib/Fund.js +103 -74
- package/lib/Interaction.js +182 -141
- package/lib/Investment.js +58 -49
- package/lib/LimitedPartner.js +241 -241
- package/lib/LimitedPartnerCampaign.js +59 -49
- package/lib/LimitedPartnerCommunication.js +91 -77
- package/lib/LimitedPartnerContactGroup.js +31 -33
- package/lib/LimitedPartnerReportGenerator.js +13 -9
- package/lib/List.js +68 -42
- package/lib/Meeting.js +56 -33
- package/lib/Message.js +225 -173
- package/lib/MessageRecipient.js +42 -31
- package/lib/News.js +30 -19
- package/lib/Note.js +40 -33
- package/lib/Organization.js +570 -506
- package/lib/Person.js +281 -246
- package/lib/Rate.js +24 -17
- package/lib/Round.js +309 -311
- package/lib/Snapshot.js +14 -9
- package/lib/Sync.js +19 -11
- package/lib/Webhook.js +8 -3
- package/package.json +1 -1
package/lib/Round.js
CHANGED
|
@@ -258,12 +258,10 @@ module.exports = function(mongoose, config) {
|
|
|
258
258
|
// Statics operate on the entire collection
|
|
259
259
|
//////////////////////////////////////////////////////\
|
|
260
260
|
|
|
261
|
-
Round.statics.getByOrg = function getByOrg(orgId, options, cb) {
|
|
261
|
+
Round.statics.getByOrg = async function getByOrg(orgId, options, cb) {
|
|
262
262
|
|
|
263
263
|
// Gets all the rounds an org has raised
|
|
264
264
|
|
|
265
|
-
const self = this;
|
|
266
|
-
|
|
267
265
|
if (!cb) { throw new Error('cb is required'); }
|
|
268
266
|
if (!orgId) { throw new Error('orgId is required'); }
|
|
269
267
|
if (!mongoose.Types.ObjectId.isValid(orgId)) { return cb(new Error('orgId is not a valid ObjectId'), null); }
|
|
@@ -276,25 +274,27 @@ module.exports = function(mongoose, config) {
|
|
|
276
274
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
277
275
|
}
|
|
278
276
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
277
|
+
try {
|
|
278
|
+
let query = this.find({
|
|
279
|
+
'deleted': { $ne: true },
|
|
280
|
+
'organization': orgId
|
|
281
|
+
});
|
|
283
282
|
|
|
284
|
-
|
|
285
|
-
|
|
283
|
+
query.populate('organization', 'name logoUrl website websiteAliases');
|
|
284
|
+
query.populate('vehicles.fund', 'name shortName');
|
|
286
285
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
286
|
+
if (options.isWorkerProcess) {
|
|
287
|
+
query.populate('vehicles.investments');
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
query.populate({
|
|
291
|
+
path: 'vehicles.investments',
|
|
292
|
+
match: { customer: options.CUSTOMER_ID }
|
|
293
|
+
});
|
|
294
|
+
}
|
|
296
295
|
|
|
297
|
-
|
|
296
|
+
let rounds = await query;
|
|
297
|
+
if (!rounds || rounds.length === 0) { return cb(null, []); }
|
|
298
298
|
|
|
299
299
|
let error = checkForUnpopulatedData(rounds, 'Round.getByOrg');
|
|
300
300
|
if (error) { return cb(error, null); }
|
|
@@ -313,14 +313,13 @@ module.exports = function(mongoose, config) {
|
|
|
313
313
|
}).reverse();
|
|
314
314
|
|
|
315
315
|
return cb(null, rounds);
|
|
316
|
-
|
|
317
|
-
|
|
316
|
+
} catch(err) {
|
|
317
|
+
return cb(err);
|
|
318
|
+
}
|
|
318
319
|
|
|
319
320
|
};
|
|
320
321
|
|
|
321
|
-
Round.statics.getByOrgs = function getByOrg(orgIds, options, cb) {
|
|
322
|
-
|
|
323
|
-
const self = this;
|
|
322
|
+
Round.statics.getByOrgs = async function getByOrg(orgIds, options, cb) {
|
|
324
323
|
|
|
325
324
|
if (!cb) { throw new Error('cb is required'); }
|
|
326
325
|
if (!orgIds) { throw new Error('orgIds is required'); }
|
|
@@ -333,25 +332,27 @@ module.exports = function(mongoose, config) {
|
|
|
333
332
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
334
333
|
}
|
|
335
334
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
335
|
+
try {
|
|
336
|
+
let query = this.find({
|
|
337
|
+
'deleted': { $ne: true },
|
|
338
|
+
'organization': { $in: orgIds }
|
|
339
|
+
});
|
|
340
340
|
|
|
341
|
-
|
|
342
|
-
|
|
341
|
+
query.populate('organization', 'name logoUrl website websiteAliases operating');
|
|
342
|
+
query.populate('vehicles.fund');
|
|
343
343
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
344
|
+
if (options.isWorkerProcess) {
|
|
345
|
+
query.populate('vehicles.investments');
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
query.populate({
|
|
349
|
+
path: 'vehicles.investments',
|
|
350
|
+
match: { customer: options.CUSTOMER_ID }
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
353
|
|
|
354
|
-
|
|
354
|
+
let rounds = await query;
|
|
355
|
+
if (!rounds || rounds.length === 0) return cb(null, []);
|
|
355
356
|
|
|
356
357
|
let error = checkForUnpopulatedData(rounds, 'Round.getByOrgs');
|
|
357
358
|
if (error) return cb(error, null);
|
|
@@ -370,14 +371,13 @@ module.exports = function(mongoose, config) {
|
|
|
370
371
|
}).reverse();
|
|
371
372
|
|
|
372
373
|
return cb(null, rounds);
|
|
373
|
-
|
|
374
|
-
|
|
374
|
+
} catch(err) {
|
|
375
|
+
return cb(err);
|
|
376
|
+
}
|
|
375
377
|
|
|
376
378
|
};
|
|
377
379
|
|
|
378
|
-
Round.statics.getByOrgs2 = function getByOrg2(orgIds, options, cb) {
|
|
379
|
-
|
|
380
|
-
const self = this;
|
|
380
|
+
Round.statics.getByOrgs2 = async function getByOrg2(orgIds, options, cb) {
|
|
381
381
|
|
|
382
382
|
if (!cb) { throw new Error('cb is required'); }
|
|
383
383
|
if (!orgIds) { throw new Error('orgIds is required'); }
|
|
@@ -390,29 +390,30 @@ module.exports = function(mongoose, config) {
|
|
|
390
390
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
391
391
|
}
|
|
392
392
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
if (options.isWorkerProcess) {
|
|
398
|
-
query.populate('vehicles.investments');
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
query.populate({
|
|
402
|
-
path: 'vehicles.investments',
|
|
403
|
-
match: { customer: options.CUSTOMER_ID }
|
|
393
|
+
try {
|
|
394
|
+
let query = this.find({
|
|
395
|
+
'organization': { $in: orgIds }
|
|
404
396
|
});
|
|
405
|
-
}
|
|
406
397
|
|
|
407
|
-
|
|
398
|
+
if (options.isWorkerProcess) {
|
|
399
|
+
query.populate('vehicles.investments');
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
query.populate({
|
|
403
|
+
path: 'vehicles.investments',
|
|
404
|
+
match: { customer: options.CUSTOMER_ID }
|
|
405
|
+
});
|
|
406
|
+
}
|
|
408
407
|
|
|
409
|
-
|
|
408
|
+
const rounds = await query;
|
|
409
|
+
return cb(null, rounds);
|
|
410
|
+
} catch(err) {
|
|
411
|
+
return cb(err);
|
|
412
|
+
}
|
|
410
413
|
|
|
411
414
|
};
|
|
412
415
|
|
|
413
|
-
Round.statics.getFundInvestments = function getFundInvestments(fundId, options, cb) {
|
|
414
|
-
|
|
415
|
-
const self = this;
|
|
416
|
+
Round.statics.getFundInvestments = async function getFundInvestments(fundId, options, cb) {
|
|
416
417
|
|
|
417
418
|
if (!cb) { throw new Error('cb is required'); }
|
|
418
419
|
if (!fundId) { throw new Error('fundId is required'); }
|
|
@@ -426,21 +427,23 @@ module.exports = function(mongoose, config) {
|
|
|
426
427
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
427
428
|
}
|
|
428
429
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
430
|
+
try {
|
|
431
|
+
let query = this.find({ 'vehicles.fund': fundId });
|
|
432
|
+
query.select('organization roundName vehicles');
|
|
433
|
+
query.populate('organization', 'name aliases description logoUrl website websiteAliases filters status ipo closed acquired operating');
|
|
432
434
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
435
|
+
if (options.isWorkerProcess) {
|
|
436
|
+
query.populate('vehicles.investments');
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
query.populate({
|
|
440
|
+
path: 'vehicles.investments',
|
|
441
|
+
match: { customer: options.CUSTOMER_ID }
|
|
442
|
+
});
|
|
443
|
+
}
|
|
442
444
|
|
|
443
|
-
|
|
445
|
+
const rounds = await query;
|
|
446
|
+
if (!rounds) return cb(null, []);
|
|
444
447
|
|
|
445
448
|
if (!options.isWorkerProcess) {
|
|
446
449
|
_.each(rounds, function(round) {
|
|
@@ -461,14 +464,13 @@ module.exports = function(mongoose, config) {
|
|
|
461
464
|
});
|
|
462
465
|
|
|
463
466
|
return cb(null, fundInvestments);
|
|
464
|
-
|
|
465
|
-
|
|
467
|
+
} catch(err) {
|
|
468
|
+
return cb(err);
|
|
469
|
+
}
|
|
466
470
|
|
|
467
471
|
};
|
|
468
|
-
|
|
469
|
-
Round.statics.getPortfolioInvestments = function getPortfolioInvestments(options, cb) {
|
|
470
472
|
|
|
471
|
-
|
|
473
|
+
Round.statics.getPortfolioInvestments = async function getPortfolioInvestments(options, cb) {
|
|
472
474
|
|
|
473
475
|
if (!cb) { throw new Error('cb is required'); }
|
|
474
476
|
if (!options) { return cb(new Error('options is required'), null); }
|
|
@@ -481,7 +483,7 @@ module.exports = function(mongoose, config) {
|
|
|
481
483
|
}
|
|
482
484
|
|
|
483
485
|
// First get the customer's fund IDs
|
|
484
|
-
Organization.getById(options.CUSTOMER_ID, { CUSTOMER_ID: options.CUSTOMER_ID },
|
|
486
|
+
Organization.getById(options.CUSTOMER_ID, { CUSTOMER_ID: options.CUSTOMER_ID }, async (err, customer) => {
|
|
485
487
|
|
|
486
488
|
if (err) return cb(err, null);
|
|
487
489
|
if (!customer) return cb(new Error('Customer not found'), null);
|
|
@@ -489,21 +491,23 @@ module.exports = function(mongoose, config) {
|
|
|
489
491
|
|
|
490
492
|
const fundIds = _.pluck(customer.funds, '_id');
|
|
491
493
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
494
|
+
try {
|
|
495
|
+
let query = this.find({ 'vehicles.fund': { $in: fundIds } });
|
|
496
|
+
query.select('organization roundName vehicles');
|
|
497
|
+
query.populate('organization', 'name description logoUrl website websiteAliases filters status ipo closed acquired operating');
|
|
495
498
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
499
|
+
if (options.isWorkerProcess) {
|
|
500
|
+
query.populate('vehicles.investments');
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
query.populate({
|
|
504
|
+
path: 'vehicles.investments',
|
|
505
|
+
match: { customer: options.CUSTOMER_ID }
|
|
506
|
+
});
|
|
507
|
+
}
|
|
505
508
|
|
|
506
|
-
|
|
509
|
+
const rounds = await query;
|
|
510
|
+
if (!rounds) return cb(null, []);
|
|
507
511
|
|
|
508
512
|
if (!options.isWorkerProcess) {
|
|
509
513
|
_.each(rounds, function(round) {
|
|
@@ -524,38 +528,38 @@ module.exports = function(mongoose, config) {
|
|
|
524
528
|
});
|
|
525
529
|
|
|
526
530
|
return cb(null, portfolioInvestments);
|
|
527
|
-
|
|
528
|
-
|
|
531
|
+
} catch(err) {
|
|
532
|
+
return cb(err);
|
|
533
|
+
}
|
|
529
534
|
|
|
530
535
|
});
|
|
531
536
|
|
|
532
537
|
};
|
|
533
538
|
|
|
534
|
-
Round.statics.getFundPerformance = function getFundPerformance(fundId, options, cb) {
|
|
539
|
+
Round.statics.getFundPerformance = async function getFundPerformance(fundId, options, cb) {
|
|
535
540
|
|
|
536
541
|
if (!cb) { throw new Error('cb is required'); }
|
|
537
542
|
if (!fundId) { throw new Error('fundId is required'); }
|
|
538
543
|
if (!mongoose.Types.ObjectId.isValid(fundId)) { return cb(new Error('fundId is not a valid ObjectId'), null); }
|
|
539
544
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
let query = self.find({ 'vehicles.fund': fundId });
|
|
545
|
+
try {
|
|
546
|
+
let query = this.find({ 'vehicles.fund': fundId });
|
|
543
547
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
548
|
+
query.select('organization vehicles');
|
|
549
|
+
query.populate('organization', 'name slug logoUrl description ');
|
|
550
|
+
query.populate('vehicles.fund');
|
|
547
551
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
552
|
+
if (options.isWorkerProcess) {
|
|
553
|
+
query.populate('vehicles.investments');
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
query.populate({
|
|
557
|
+
path: 'vehicles.investments',
|
|
558
|
+
match: { customer: options.CUSTOMER_ID }
|
|
559
|
+
});
|
|
560
|
+
}
|
|
557
561
|
|
|
558
|
-
|
|
562
|
+
const rounds = await query;
|
|
559
563
|
if (!rounds) return cb(null, null);
|
|
560
564
|
else if (rounds.length === 0) return cb(null, []);
|
|
561
565
|
|
|
@@ -567,14 +571,13 @@ module.exports = function(mongoose, config) {
|
|
|
567
571
|
}
|
|
568
572
|
|
|
569
573
|
return cb(null, calculatePerformance(rounds));
|
|
570
|
-
|
|
571
|
-
|
|
574
|
+
} catch(err) {
|
|
575
|
+
return cb(err);
|
|
576
|
+
}
|
|
572
577
|
|
|
573
578
|
};
|
|
574
579
|
|
|
575
|
-
Round.statics.getPortfolioByFund = function getPortfolioByFund(fundId, options, cb) {
|
|
576
|
-
|
|
577
|
-
const self = this;
|
|
580
|
+
Round.statics.getPortfolioByFund = async function getPortfolioByFund(fundId, options, cb) {
|
|
578
581
|
|
|
579
582
|
if (!cb) { throw new Error('cb is required'); }
|
|
580
583
|
if (!fundId) { throw new Error('fundId is required'); }
|
|
@@ -588,23 +591,25 @@ module.exports = function(mongoose, config) {
|
|
|
588
591
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
589
592
|
}
|
|
590
593
|
|
|
591
|
-
|
|
594
|
+
try {
|
|
595
|
+
let query = this.find({ 'vehicles.fund': fundId });
|
|
592
596
|
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
597
|
+
query.select('organization vehicles');
|
|
598
|
+
query.populate('organization', 'name aliases slug logoUrl description contact filters status ipo closed acquired operating website websiteAliases');
|
|
599
|
+
query.populate('vehicles.fund');
|
|
596
600
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
601
|
+
if (options.isWorkerProcess) {
|
|
602
|
+
query.populate('vehicles.investments');
|
|
603
|
+
}
|
|
604
|
+
else {
|
|
605
|
+
query.populate({
|
|
606
|
+
path: 'vehicles.investments',
|
|
607
|
+
match: { customer: options.CUSTOMER_ID }
|
|
608
|
+
});
|
|
609
|
+
}
|
|
606
610
|
|
|
607
|
-
|
|
611
|
+
const rounds = await query;
|
|
612
|
+
if (!rounds || rounds.length === 0) return cb(null, []);
|
|
608
613
|
|
|
609
614
|
let error = checkForUnpopulatedData(rounds, 'Round.getPortfolioByFund');
|
|
610
615
|
if (error) return cb(error, null);
|
|
@@ -617,18 +622,17 @@ module.exports = function(mongoose, config) {
|
|
|
617
622
|
}
|
|
618
623
|
|
|
619
624
|
return cb(null, buildPortfolio(rounds, [fundId]));
|
|
620
|
-
|
|
621
|
-
|
|
625
|
+
} catch(err) {
|
|
626
|
+
return cb(err);
|
|
627
|
+
}
|
|
622
628
|
|
|
623
629
|
};
|
|
624
630
|
|
|
625
|
-
Round.statics.getPortfolioByFunds = function getPortfolioByFunds(fundIds, options, cb) {
|
|
631
|
+
Round.statics.getPortfolioByFunds = async function getPortfolioByFunds(fundIds, options, cb) {
|
|
626
632
|
|
|
627
633
|
// Returns a list of orgs that have rounds participated in by the given fund ids
|
|
628
634
|
// Note retrieving multiple funds does not calculate fund stats. Use getPortfolioByFund for that.
|
|
629
635
|
|
|
630
|
-
const self = this;
|
|
631
|
-
|
|
632
636
|
if (!cb) { throw new Error('cb is required'); }
|
|
633
637
|
if (!fundIds) { throw new Error('fundIds is required'); }
|
|
634
638
|
if (!options) { return cb(new Error('options is required'), null); }
|
|
@@ -640,30 +644,32 @@ module.exports = function(mongoose, config) {
|
|
|
640
644
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
641
645
|
}
|
|
642
646
|
|
|
643
|
-
|
|
647
|
+
try {
|
|
648
|
+
let query = this.find({ 'vehicles.fund': { $in: fundIds } });
|
|
644
649
|
|
|
645
|
-
|
|
646
|
-
query.populate({
|
|
647
|
-
path: 'organization',
|
|
648
|
-
select: 'name aliases slug logoUrl description contact chairs filters status ipo closed acquired operating website websiteAliases',
|
|
649
|
-
populate: [
|
|
650
|
-
{ path: 'chairs.first', select: 'name avatarUrl title doNotDisplay' },
|
|
651
|
-
{ path: 'chairs.second', select: 'name avatarUrl title doNotDisplay' }
|
|
652
|
-
]
|
|
653
|
-
});
|
|
654
|
-
query.populate('vehicles.fund');
|
|
655
|
-
|
|
656
|
-
if (options.isWorkerProcess) {
|
|
657
|
-
query.populate('vehicles.investments');
|
|
658
|
-
}
|
|
659
|
-
else {
|
|
650
|
+
query.select('organization vehicles');
|
|
660
651
|
query.populate({
|
|
661
|
-
path: '
|
|
662
|
-
|
|
652
|
+
path: 'organization',
|
|
653
|
+
select: 'name aliases slug logoUrl description contact chairs filters status ipo closed acquired operating website websiteAliases',
|
|
654
|
+
populate: [
|
|
655
|
+
{ path: 'chairs.first', select: 'name avatarUrl title doNotDisplay' },
|
|
656
|
+
{ path: 'chairs.second', select: 'name avatarUrl title doNotDisplay' }
|
|
657
|
+
]
|
|
663
658
|
});
|
|
664
|
-
|
|
659
|
+
query.populate('vehicles.fund');
|
|
660
|
+
|
|
661
|
+
if (options.isWorkerProcess) {
|
|
662
|
+
query.populate('vehicles.investments');
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
query.populate({
|
|
666
|
+
path: 'vehicles.investments',
|
|
667
|
+
match: { customer: options.CUSTOMER_ID }
|
|
668
|
+
});
|
|
669
|
+
}
|
|
665
670
|
|
|
666
|
-
|
|
671
|
+
const rounds = await query;
|
|
672
|
+
if (!rounds || rounds.length === 0) return cb(null, []);
|
|
667
673
|
|
|
668
674
|
let error = checkForUnpopulatedData(rounds, 'Round.getPortfolioByFunds');
|
|
669
675
|
if (error) return cb(error, null);
|
|
@@ -676,18 +682,17 @@ module.exports = function(mongoose, config) {
|
|
|
676
682
|
}
|
|
677
683
|
|
|
678
684
|
return cb(null, buildPortfolio(rounds, fundIds));
|
|
679
|
-
|
|
680
|
-
|
|
685
|
+
} catch(err) {
|
|
686
|
+
return cb(err);
|
|
687
|
+
}
|
|
681
688
|
|
|
682
689
|
};
|
|
683
690
|
|
|
684
|
-
Round.statics.getPortfolioList = function getPortfolioList(fundIds, options, cb) {
|
|
691
|
+
Round.statics.getPortfolioList = async function getPortfolioList(fundIds, options, cb) {
|
|
685
692
|
|
|
686
693
|
// Returns a list of orgs that have rounds participated in by the given fund ids
|
|
687
694
|
// Note retrieving multiple funds does not calculate fund stats. Use getPortfolioByFund for that.
|
|
688
695
|
|
|
689
|
-
const self = this;
|
|
690
|
-
|
|
691
696
|
if (!cb) { throw new Error('cb is required'); }
|
|
692
697
|
if (!fundIds) { throw new Error('fundIds is required'); }
|
|
693
698
|
if (!options) { return cb(new Error('options is required'), null); }
|
|
@@ -696,16 +701,21 @@ module.exports = function(mongoose, config) {
|
|
|
696
701
|
|
|
697
702
|
options = helpers.getDefaultOptions(options);
|
|
698
703
|
|
|
699
|
-
|
|
704
|
+
try {
|
|
705
|
+
let query = this.find({ 'vehicles.fund': { $in: fundIds } });
|
|
700
706
|
|
|
701
|
-
|
|
702
|
-
|
|
707
|
+
query.select('organization vehicles');
|
|
708
|
+
query.populate('organization', 'name website status ipo operating people');
|
|
709
|
+
query.lean({ virtuals: true });
|
|
703
710
|
|
|
704
|
-
|
|
711
|
+
const rounds = await query;
|
|
712
|
+
if (!rounds || rounds.length === 0) {
|
|
713
|
+
process.nextTick(function() { cb(null, []); });
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
705
716
|
|
|
706
717
|
if (!options.isWorkerProcess) {
|
|
707
718
|
_.each(rounds, function(round) {
|
|
708
|
-
round.organization = round.organization.toObject({ virtuals: true });
|
|
709
719
|
round = helpers.cleanRound(round, fundIds, options.CUSTOMER_ID);
|
|
710
720
|
round.organization = helpers.cleanOrg(round.organization, options.CUSTOMER_ID);
|
|
711
721
|
});
|
|
@@ -715,7 +725,7 @@ module.exports = function(mongoose, config) {
|
|
|
715
725
|
const grouped = _.groupBy(rounds, function(r) { return r.organization._id; });
|
|
716
726
|
|
|
717
727
|
_.each(grouped, function(rounds) {
|
|
718
|
-
|
|
728
|
+
|
|
719
729
|
var fundList = _.uniq(_.flatten(_.map(rounds, function(round) {
|
|
720
730
|
return round.vehicles ? _.map(round.vehicles, function(vehicle) { return vehicle.fund.toString(); }) : [];
|
|
721
731
|
})));
|
|
@@ -734,13 +744,14 @@ module.exports = function(mongoose, config) {
|
|
|
734
744
|
|
|
735
745
|
portfolio = _.sortBy(portfolio, function(p) { return p.name.toLowerCase(); });
|
|
736
746
|
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
747
|
+
process.nextTick(function() { cb(null, portfolio); });
|
|
748
|
+
} catch(err) {
|
|
749
|
+
process.nextTick(function() { cb(err); });
|
|
750
|
+
}
|
|
740
751
|
|
|
741
752
|
};
|
|
742
753
|
|
|
743
|
-
Round.statics.removeInvestment = function(investmentId, cb) {
|
|
754
|
+
Round.statics.removeInvestment = async function(investmentId, cb) {
|
|
744
755
|
|
|
745
756
|
// Do not call this directly. It will leave an orphaned investment document.
|
|
746
757
|
// The preferred way to delete an investment is to delete it directly and this
|
|
@@ -750,48 +761,42 @@ module.exports = function(mongoose, config) {
|
|
|
750
761
|
if (!investmentId) { throw new Error('investmentId is required'); }
|
|
751
762
|
if (!mongoose.Types.ObjectId.isValid(investmentId)) { return cb(new Error('investmentId is not a valid ObjectId'), null); }
|
|
752
763
|
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
let getRounds = function getRounds(callback) {
|
|
756
|
-
let query = self.find({ 'vehicles.investments': investmentId });
|
|
764
|
+
try {
|
|
765
|
+
let query = this.find({ 'vehicles.investments': investmentId });
|
|
757
766
|
query.select('_id');
|
|
758
|
-
|
|
759
|
-
};
|
|
767
|
+
const rounds = await query;
|
|
760
768
|
|
|
761
|
-
|
|
762
|
-
let query = self.updateMany(
|
|
769
|
+
let updateQuery = this.updateMany(
|
|
763
770
|
{ 'vehicles.investments': investmentId },
|
|
764
|
-
{ $pull : { 'vehicles.$.investments': investmentId } }
|
|
765
|
-
{ multi : true }
|
|
771
|
+
{ $pull : { 'vehicles.$.investments': investmentId } }
|
|
766
772
|
);
|
|
767
|
-
|
|
768
|
-
};
|
|
773
|
+
const result = await updateQuery;
|
|
769
774
|
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
775
|
+
return cb(null, result);
|
|
776
|
+
} catch(err) {
|
|
777
|
+
return cb(err);
|
|
778
|
+
}
|
|
774
779
|
|
|
775
780
|
};
|
|
776
781
|
|
|
777
|
-
Round.statics.removeVehicle = function(roundId, fundId, cb) {
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
)
|
|
787
|
-
|
|
782
|
+
Round.statics.removeVehicle = async function(roundId, fundId, cb) {
|
|
783
|
+
|
|
784
|
+
try {
|
|
785
|
+
const result = await this
|
|
786
|
+
.findOneAndUpdate(
|
|
787
|
+
{ '_id': roundId },
|
|
788
|
+
{ $pull : { 'vehicles': { 'fund': fundId } } },
|
|
789
|
+
{ multi : false }
|
|
790
|
+
);
|
|
791
|
+
return cb(null, result);
|
|
792
|
+
} catch(err) {
|
|
793
|
+
return cb(err);
|
|
794
|
+
}
|
|
788
795
|
|
|
789
796
|
};
|
|
790
797
|
|
|
791
|
-
Round.statics.getRelated = function getRelated(orgid, options, cb) {
|
|
798
|
+
Round.statics.getRelated = async function getRelated(orgid, options, cb) {
|
|
792
799
|
|
|
793
|
-
const self = this;
|
|
794
|
-
const async = require('async');
|
|
795
800
|
const Organization = mongoose.model('Organization');
|
|
796
801
|
|
|
797
802
|
if (!cb) { throw new Error('cb is required'); }
|
|
@@ -805,109 +810,97 @@ module.exports = function(mongoose, config) {
|
|
|
805
810
|
var customerFunds = options.customerFunds;
|
|
806
811
|
if (!customerFunds) {
|
|
807
812
|
const Fund = mongoose.model('Fund');
|
|
808
|
-
return Fund.findByCustomer(options.CUSTOMER_ID,
|
|
813
|
+
return Fund.findByCustomer(options.CUSTOMER_ID, (err, funds) => {
|
|
809
814
|
if (err) return cb(err);
|
|
810
815
|
options.customerFunds = funds;
|
|
811
|
-
return
|
|
816
|
+
return this.getRelated(orgid, options, cb);
|
|
812
817
|
});
|
|
813
818
|
}
|
|
814
819
|
|
|
815
|
-
|
|
816
|
-
|
|
820
|
+
try {
|
|
817
821
|
// Find organizations acquired by this org (acquirees)
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
$
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
.exec().then(function(result) { callback(null, result); }).catch(function(err) { callback(err); });
|
|
828
|
-
},
|
|
829
|
-
|
|
822
|
+
const acquirees = await Organization
|
|
823
|
+
.find({
|
|
824
|
+
$or: [
|
|
825
|
+
{ 'operating.acquired.private.by': orgid, 'operating.acquired.private.customer': options.CUSTOMER_ID, 'deleted': { $ne: true } },
|
|
826
|
+
{ 'operating.acquired.public.by': orgid, 'deleted': { $ne: true } }
|
|
827
|
+
]
|
|
828
|
+
})
|
|
829
|
+
.select('name logoUrl');
|
|
830
|
+
|
|
830
831
|
// Find organizations merged with this org
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
$
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
.exec().then(function(result) { callback(null, result); }).catch(function(err) { callback(err); });
|
|
841
|
-
},
|
|
842
|
-
|
|
832
|
+
const merged = await Organization
|
|
833
|
+
.find({
|
|
834
|
+
$or: [
|
|
835
|
+
{ 'operating.merged.private.with': orgid, 'operating.merged.private.customer': options.CUSTOMER_ID, 'deleted': { $ne: true } },
|
|
836
|
+
{ 'operating.merged.public.with': orgid, 'deleted': { $ne: true } }
|
|
837
|
+
]
|
|
838
|
+
})
|
|
839
|
+
.select('name logoUrl');
|
|
840
|
+
|
|
843
841
|
// Find organizations that acquired this org (acquirers) or merged with this org
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
}
|
|
860
|
-
});
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
if (mainOrg.operating.acquired.public && mainOrg.operating.acquired.public.by) {
|
|
864
|
-
relatedIds.push(mainOrg.operating.acquired.public.by);
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
// Check for merger partner
|
|
869
|
-
if (mainOrg.operating && mainOrg.operating.merged) {
|
|
870
|
-
// merged.private is an array, iterate through it
|
|
871
|
-
if (mainOrg.operating.merged.private && Array.isArray(mainOrg.operating.merged.private)) {
|
|
872
|
-
mainOrg.operating.merged.private.forEach(function(mergedEntry) {
|
|
873
|
-
if (mergedEntry && mergedEntry.with) {
|
|
874
|
-
relatedIds.push(mergedEntry.with);
|
|
875
|
-
}
|
|
876
|
-
});
|
|
842
|
+
const mainOrg = await Organization
|
|
843
|
+
.findById(orgid)
|
|
844
|
+
.select('operating');
|
|
845
|
+
|
|
846
|
+
let reverseRelated = [];
|
|
847
|
+
if (mainOrg) {
|
|
848
|
+
var relatedIds = [];
|
|
849
|
+
|
|
850
|
+
// Check for acquirer
|
|
851
|
+
if (mainOrg.operating && mainOrg.operating.acquired) {
|
|
852
|
+
// acquired.private is an array, iterate through it
|
|
853
|
+
if (mainOrg.operating.acquired.private && Array.isArray(mainOrg.operating.acquired.private)) {
|
|
854
|
+
mainOrg.operating.acquired.private.forEach(function(acquiredEntry) {
|
|
855
|
+
if (acquiredEntry && acquiredEntry.by) {
|
|
856
|
+
relatedIds.push(acquiredEntry.by);
|
|
877
857
|
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
if (mainOrg.operating.acquired.public && mainOrg.operating.acquired.public.by) {
|
|
862
|
+
relatedIds.push(mainOrg.operating.acquired.public.by);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
// Check for merger partner
|
|
867
|
+
if (mainOrg.operating && mainOrg.operating.merged) {
|
|
868
|
+
// merged.private is an array, iterate through it
|
|
869
|
+
if (mainOrg.operating.merged.private && Array.isArray(mainOrg.operating.merged.private)) {
|
|
870
|
+
mainOrg.operating.merged.private.forEach(function(mergedEntry) {
|
|
871
|
+
if (mergedEntry && mergedEntry.with) {
|
|
872
|
+
relatedIds.push(mergedEntry.with);
|
|
881
873
|
}
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
if (mainOrg.operating.merged.public && mainOrg.operating.merged.public.with) {
|
|
878
|
+
relatedIds.push(mainOrg.operating.merged.public.with);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
if (relatedIds.length > 0) {
|
|
883
|
+
reverseRelated = await Organization
|
|
884
|
+
.find({
|
|
885
|
+
'_id': { $in: relatedIds },
|
|
886
|
+
'deleted': { $ne: true }
|
|
887
|
+
})
|
|
888
|
+
.select('name logoUrl');
|
|
889
|
+
}
|
|
894
890
|
}
|
|
895
|
-
|
|
896
|
-
], function(err, results) {
|
|
897
|
-
if (err) return cb(err);
|
|
898
|
-
|
|
891
|
+
|
|
899
892
|
// Flatten and combine all results
|
|
900
893
|
var allResults = [];
|
|
901
|
-
|
|
894
|
+
[acquirees, merged, reverseRelated].forEach(function(resultSet) {
|
|
902
895
|
if (Array.isArray(resultSet)) {
|
|
903
896
|
allResults = allResults.concat(resultSet);
|
|
904
897
|
}
|
|
905
898
|
});
|
|
906
|
-
|
|
899
|
+
|
|
907
900
|
// Remove duplicates and the org itself
|
|
908
901
|
var uniqueResults = [];
|
|
909
902
|
var seenIds = new Set();
|
|
910
|
-
|
|
903
|
+
|
|
911
904
|
allResults.forEach(function(org) {
|
|
912
905
|
if (!seenIds.has(org._id.toString()) && org._id.toString() !== orgid.toString()) {
|
|
913
906
|
seenIds.add(org._id.toString());
|
|
@@ -916,11 +909,10 @@ module.exports = function(mongoose, config) {
|
|
|
916
909
|
});
|
|
917
910
|
|
|
918
911
|
// Now get rounds for each related organization
|
|
919
|
-
|
|
920
|
-
|
|
912
|
+
const relatedWithRounds = await Promise.all(uniqueResults.map(async (org) => {
|
|
921
913
|
var fundIds = customerFunds.map(function(fund) { return fund._id; });
|
|
922
|
-
|
|
923
|
-
|
|
914
|
+
|
|
915
|
+
let rounds = await this
|
|
924
916
|
.find({
|
|
925
917
|
'organization': org._id,
|
|
926
918
|
'vehicles.fund': { $in: fundIds },
|
|
@@ -931,31 +923,37 @@ module.exports = function(mongoose, config) {
|
|
|
931
923
|
.populate({
|
|
932
924
|
path: 'vehicles.investments',
|
|
933
925
|
match: { customer: options.CUSTOMER_ID }
|
|
934
|
-
})
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
}
|
|
926
|
+
});
|
|
927
|
+
|
|
928
|
+
// Clean rounds to only show vehicles for customer funds
|
|
929
|
+
if (rounds && !options.isWorkerProcess) {
|
|
930
|
+
rounds = rounds.map(function(round) {
|
|
931
|
+
return helpers.cleanRound(round, fundIds, options.CUSTOMER_ID);
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
return {
|
|
936
|
+
org: org,
|
|
937
|
+
rounds: rounds || []
|
|
938
|
+
};
|
|
939
|
+
}));
|
|
940
|
+
|
|
941
|
+
return cb(null, relatedWithRounds);
|
|
942
|
+
} catch(err) {
|
|
943
|
+
return cb(err);
|
|
944
|
+
}
|
|
953
945
|
};
|
|
954
946
|
|
|
955
|
-
Round.statics.upsert = function(round, cb) {
|
|
947
|
+
Round.statics.upsert = async function(round, cb) {
|
|
956
948
|
|
|
957
949
|
if (!round) { return cb(new Error('round is required'), null); }
|
|
958
|
-
|
|
950
|
+
|
|
951
|
+
try {
|
|
952
|
+
const result = await round.save();
|
|
953
|
+
return cb(null, result);
|
|
954
|
+
} catch(err) {
|
|
955
|
+
return cb(err);
|
|
956
|
+
}
|
|
959
957
|
|
|
960
958
|
};
|
|
961
959
|
|
|
@@ -970,4 +968,4 @@ module.exports = function(mongoose, config) {
|
|
|
970
968
|
|
|
971
969
|
mongoose.model('Round', Round);
|
|
972
970
|
|
|
973
|
-
};
|
|
971
|
+
};
|