@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/LimitedPartner.js
CHANGED
|
@@ -8,7 +8,6 @@ module.exports = function(mongoose, config) {
|
|
|
8
8
|
Note = mongoose.model('Note'),
|
|
9
9
|
Organization = mongoose.model('Organization'),
|
|
10
10
|
_ = require('underscore'),
|
|
11
|
-
async = require('async'),
|
|
12
11
|
helpers = require('../helpers');
|
|
13
12
|
|
|
14
13
|
let LimitedPartner = new Schema({
|
|
@@ -331,30 +330,23 @@ module.exports = function(mongoose, config) {
|
|
|
331
330
|
Note.createForModel(this, lpId, note, cb);
|
|
332
331
|
};
|
|
333
332
|
|
|
334
|
-
LimitedPartner.statics.deleteNote = function(noteId, customerId, cb) {
|
|
333
|
+
LimitedPartner.statics.deleteNote = async function(noteId, customerId, cb) {
|
|
335
334
|
|
|
336
335
|
// Delete the note itself along with any references
|
|
337
336
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
self.updateOne({}, {
|
|
337
|
+
try {
|
|
338
|
+
await Note.delete(noteId, customerId);
|
|
339
|
+
await this.updateOne({}, {
|
|
342
340
|
$pull: { 'notes' : [noteId] }
|
|
343
|
-
})
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
removeReferences
|
|
349
|
-
], function(err, results) {
|
|
350
|
-
return cb(err, null);
|
|
351
|
-
});
|
|
341
|
+
});
|
|
342
|
+
return cb(null, null);
|
|
343
|
+
} catch(err) {
|
|
344
|
+
return cb(err);
|
|
345
|
+
}
|
|
352
346
|
|
|
353
347
|
};
|
|
354
348
|
|
|
355
|
-
LimitedPartner.statics.getById = function(id, options, cb) {
|
|
356
|
-
|
|
357
|
-
const self = this;
|
|
349
|
+
LimitedPartner.statics.getById = async function(id, options, cb) {
|
|
358
350
|
|
|
359
351
|
if (!cb) { throw new Error('cb is required'); }
|
|
360
352
|
if (!id) { return cb(new Error('id is required'), null); }
|
|
@@ -365,28 +357,29 @@ module.exports = function(mongoose, config) {
|
|
|
365
357
|
|
|
366
358
|
options = helpers.getDefaultOptions(options);
|
|
367
359
|
|
|
368
|
-
|
|
360
|
+
try {
|
|
361
|
+
let query;
|
|
369
362
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
363
|
+
if (options.isWorkerProcess) {
|
|
364
|
+
query = this.findById(id, getReadFilterKeys(options.role))
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
query = this.findOne({ '_id': id, customer: options.CUSTOMER_ID }, getReadFilterKeys(options.role));
|
|
368
|
+
}
|
|
376
369
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
370
|
+
query.populate('transactions.fund');
|
|
371
|
+
query.populate({
|
|
372
|
+
path: 'people',
|
|
373
|
+
populate: { path: 'sources.person', select: 'name avatarUrl title' }
|
|
374
|
+
});
|
|
375
|
+
query.populate({
|
|
376
|
+
path: 'notes',
|
|
377
|
+
match: { customer: options.CUSTOMER_ID },
|
|
378
|
+
populate: { path: 'createdBy', select: 'name avatarUrl' }
|
|
379
|
+
});
|
|
380
|
+
query.populate('documents');
|
|
388
381
|
|
|
389
|
-
|
|
382
|
+
const lp = await query;
|
|
390
383
|
if (!lp) { return cb(null, null); }
|
|
391
384
|
|
|
392
385
|
lp.people = _.map(lp.people, function(person) {
|
|
@@ -409,13 +402,11 @@ module.exports = function(mongoose, config) {
|
|
|
409
402
|
|
|
410
403
|
return cb(null, lp);
|
|
411
404
|
|
|
412
|
-
}
|
|
405
|
+
} catch(err) { return cb(err); }
|
|
413
406
|
|
|
414
407
|
};
|
|
415
408
|
|
|
416
|
-
LimitedPartner.statics.getByName = function(lpName, options, cb) {
|
|
417
|
-
|
|
418
|
-
const self = this;
|
|
409
|
+
LimitedPartner.statics.getByName = async function(lpName, options, cb) {
|
|
419
410
|
|
|
420
411
|
if (!cb) { throw new Error('cb is required'); }
|
|
421
412
|
if (!options) { return cb(new Error('options is required'), null); }
|
|
@@ -424,24 +415,20 @@ module.exports = function(mongoose, config) {
|
|
|
424
415
|
|
|
425
416
|
options = helpers.getDefaultOptions(options);
|
|
426
417
|
|
|
427
|
-
let query;
|
|
428
|
-
|
|
429
418
|
if (!options.isWorkerProcess) {
|
|
430
419
|
return cb(null, []);
|
|
431
420
|
}
|
|
432
421
|
|
|
433
|
-
|
|
434
|
-
query =
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
422
|
+
try {
|
|
423
|
+
let query = this.findOne({'name': lpName, customer: options.CUSTOMER_ID }, getReadFilterKeys(options.role));
|
|
424
|
+
query.populate('transactions.fund');
|
|
425
|
+
const result = await query;
|
|
426
|
+
return cb(null, result);
|
|
427
|
+
} catch(err) { return cb(err); }
|
|
439
428
|
|
|
440
429
|
};
|
|
441
430
|
|
|
442
|
-
LimitedPartner.statics.getByPersonId = function(personId, options, cb) {
|
|
443
|
-
|
|
444
|
-
const self = this;
|
|
431
|
+
LimitedPartner.statics.getByPersonId = async function(personId, options, cb) {
|
|
445
432
|
|
|
446
433
|
if (!cb) { throw new Error('cb is required'); }
|
|
447
434
|
if (!personId) { return cb(new Error('personId is required'), null); }
|
|
@@ -452,30 +439,30 @@ module.exports = function(mongoose, config) {
|
|
|
452
439
|
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
453
440
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
454
441
|
}
|
|
455
|
-
|
|
442
|
+
|
|
456
443
|
options = helpers.getDefaultOptions(options);
|
|
457
444
|
|
|
458
|
-
|
|
445
|
+
try {
|
|
446
|
+
let query;
|
|
459
447
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
448
|
+
if (options.isWorkerProcess) {
|
|
449
|
+
query = this.find({'people': personId}, getReadFilterKeys(options.role));
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
query = this.find({'people': personId, customer: options.CUSTOMER_ID }, getReadFilterKeys(options.role));
|
|
453
|
+
}
|
|
466
454
|
|
|
467
|
-
|
|
468
|
-
|
|
455
|
+
query.populate('transactions.fund');
|
|
456
|
+
query.populate('people', 'name');
|
|
469
457
|
|
|
470
|
-
|
|
458
|
+
let lps = await query;
|
|
459
|
+
lps = _.sortBy(lps, function(lp) { return lp.name ? lp.name.toLowerCase() : ''; });
|
|
471
460
|
return cb(null, lps);
|
|
472
|
-
}
|
|
461
|
+
} catch(err) { return cb(err); }
|
|
473
462
|
|
|
474
463
|
};
|
|
475
464
|
|
|
476
|
-
LimitedPartner.statics.getByPersonIds = function(personIds, options, cb) {
|
|
477
|
-
|
|
478
|
-
const self = this;
|
|
465
|
+
LimitedPartner.statics.getByPersonIds = async function(personIds, options, cb) {
|
|
479
466
|
|
|
480
467
|
if (!cb) { throw new Error('cb is required'); }
|
|
481
468
|
if (!personIds) { return cb(new Error('personIds is required'), null); }
|
|
@@ -488,24 +475,24 @@ module.exports = function(mongoose, config) {
|
|
|
488
475
|
|
|
489
476
|
options = helpers.getDefaultOptions(options);
|
|
490
477
|
|
|
491
|
-
|
|
478
|
+
try {
|
|
479
|
+
let query;
|
|
492
480
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
481
|
+
if (options.isWorkerProcess) {
|
|
482
|
+
query = this.find({'people': { $in : personIds }}, getReadFilterKeys(options.role));
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
query = this.find({'people': { $in : personIds }, customer: options.CUSTOMER_ID }, getReadFilterKeys(options.role));
|
|
486
|
+
}
|
|
499
487
|
|
|
500
|
-
|
|
488
|
+
let lps = await query;
|
|
489
|
+
lps = _.sortBy(lps, function(lp) { return lp.name ? lp.name.toLowerCase() : ''; });
|
|
501
490
|
return cb(null, lps);
|
|
502
|
-
}
|
|
491
|
+
} catch(err) { return cb(err); }
|
|
503
492
|
|
|
504
493
|
};
|
|
505
494
|
|
|
506
|
-
LimitedPartner.statics.getNotes = function getNotes(lpid, options, cb) {
|
|
507
|
-
|
|
508
|
-
const self = this;
|
|
495
|
+
LimitedPartner.statics.getNotes = async function getNotes(lpid, options, cb) {
|
|
509
496
|
|
|
510
497
|
if (!cb) { throw new Error('cb is required'); }
|
|
511
498
|
if (!lpid) { return cb(new Error('lpid is required'), null); }
|
|
@@ -514,23 +501,24 @@ module.exports = function(mongoose, config) {
|
|
|
514
501
|
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
515
502
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
516
503
|
|
|
517
|
-
|
|
504
|
+
try {
|
|
505
|
+
let query = this.findOne({ '_id': lpid, customer: options.CUSTOMER_ID });
|
|
518
506
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
507
|
+
query.select('notes people');
|
|
508
|
+
query.populate({
|
|
509
|
+
path: 'notes',
|
|
510
|
+
match: { customer: options.CUSTOMER_ID },
|
|
511
|
+
options: { sort: { createdOn: -1 } },
|
|
512
|
+
populate: { path: 'createdBy', select: 'name avatarUrl title' }
|
|
513
|
+
});
|
|
526
514
|
|
|
527
|
-
|
|
515
|
+
const result = await query;
|
|
516
|
+
return cb(null, result);
|
|
517
|
+
} catch(err) { return cb(err); }
|
|
528
518
|
|
|
529
519
|
};
|
|
530
520
|
|
|
531
|
-
LimitedPartner.statics.getSources = function(lpid, options, cb) {
|
|
532
|
-
|
|
533
|
-
const self = this;
|
|
521
|
+
LimitedPartner.statics.getSources = async function(lpid, options, cb) {
|
|
534
522
|
|
|
535
523
|
if (!cb) { throw new Error('cb is required'); }
|
|
536
524
|
if (!lpid) { return cb(new Error('lpid is required'), null); }
|
|
@@ -539,54 +527,53 @@ module.exports = function(mongoose, config) {
|
|
|
539
527
|
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
540
528
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
541
529
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
query.populate({
|
|
545
|
-
path: 'people',
|
|
546
|
-
select: 'name avatarUrl title doNotDisplay sources',
|
|
547
|
-
populate: { path: 'sources.person', select: 'name avatarUrl title doNotDisplay' }
|
|
548
|
-
});
|
|
530
|
+
try {
|
|
531
|
+
let query = this.findById(lpid);
|
|
549
532
|
|
|
550
|
-
|
|
533
|
+
query.populate({
|
|
534
|
+
path: 'people',
|
|
535
|
+
select: 'name avatarUrl title doNotDisplay sources',
|
|
536
|
+
populate: { path: 'sources.person', select: 'name avatarUrl title doNotDisplay' }
|
|
537
|
+
});
|
|
551
538
|
|
|
552
|
-
|
|
539
|
+
const lp = await query;
|
|
540
|
+
if (!lp) { return cb(null, null); }
|
|
553
541
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
let all = [];
|
|
557
|
-
let lpSources = helpers.getPeopleSources(lp.people);
|
|
542
|
+
const customer = await Organization.findById(options.CUSTOMER_ID);
|
|
543
|
+
if (!customer) { return cb(null, null); }
|
|
558
544
|
|
|
559
|
-
|
|
545
|
+
let current = [];
|
|
546
|
+
let past = [];
|
|
547
|
+
let all = [];
|
|
548
|
+
let lpSources = helpers.getPeopleSources(lp.people);
|
|
560
549
|
|
|
561
|
-
|
|
562
|
-
if (!ls || !ls.person || !ls.person._id) return false;
|
|
563
|
-
return ls.person._id.toString() === p.person.toString();
|
|
564
|
-
});
|
|
550
|
+
_.each(customer.people, function(p) {
|
|
565
551
|
|
|
566
|
-
|
|
552
|
+
let source = _.find(lpSources, function(ls) {
|
|
553
|
+
if (!ls || !ls.person || !ls.person._id) return false;
|
|
554
|
+
return ls.person._id.toString() === p.person.toString();
|
|
555
|
+
});
|
|
567
556
|
|
|
568
|
-
|
|
569
|
-
if (!p.current) { past.push(source); }
|
|
570
|
-
all.push(source);
|
|
557
|
+
if (!source) { return; }
|
|
571
558
|
|
|
572
|
-
|
|
559
|
+
if (p.current) { current.push(source); }
|
|
560
|
+
if (!p.current) { past.push(source); }
|
|
561
|
+
all.push(source);
|
|
573
562
|
|
|
574
|
-
|
|
575
|
-
return cb(null, {
|
|
576
|
-
all: all, //helpers.sortPeopleSources(all, options.CUSTOMER_ID),
|
|
577
|
-
current: current, //helpers.sortPeopleSources(current, options.CUSTOMER_ID),
|
|
578
|
-
past: past //helpers.sortPeopleSources(past, options.CUSTOMER_ID)
|
|
579
|
-
});
|
|
563
|
+
});
|
|
580
564
|
|
|
581
|
-
|
|
565
|
+
// todo - fix sorting
|
|
566
|
+
return cb(null, {
|
|
567
|
+
all: all, //helpers.sortPeopleSources(all, options.CUSTOMER_ID),
|
|
568
|
+
current: current, //helpers.sortPeopleSources(current, options.CUSTOMER_ID),
|
|
569
|
+
past: past //helpers.sortPeopleSources(past, options.CUSTOMER_ID)
|
|
570
|
+
});
|
|
582
571
|
|
|
583
|
-
}
|
|
572
|
+
} catch(err) { return cb(err); }
|
|
584
573
|
|
|
585
574
|
};
|
|
586
575
|
|
|
587
|
-
LimitedPartner.statics.list = function (customerId, options, cb) {
|
|
588
|
-
|
|
589
|
-
const self = this;
|
|
576
|
+
LimitedPartner.statics.list = async function (customerId, options, cb) {
|
|
590
577
|
|
|
591
578
|
if (!cb) { throw new Error('cb is required'); }
|
|
592
579
|
if (!customerId) { return cb(new Error('customerId is required'), null); }
|
|
@@ -595,19 +582,23 @@ module.exports = function(mongoose, config) {
|
|
|
595
582
|
|
|
596
583
|
options = helpers.getDefaultOptions(options);
|
|
597
584
|
|
|
598
|
-
|
|
585
|
+
try {
|
|
586
|
+
let query;
|
|
599
587
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
588
|
+
if (options.isWorkerProcess) {
|
|
589
|
+
query = this.find({}, getReadFilterKeys(options.role));
|
|
590
|
+
}
|
|
591
|
+
else {
|
|
592
|
+
query = this.find({ 'transactions.fund': { $in : options.fundids }, customer: customerId }, getReadFilterKeys(options.role));
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
query.populate('transactions.fund');
|
|
596
|
+
query.populate('people');
|
|
597
|
+
query.sort({ 'name': -1 });
|
|
606
598
|
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
query.exec().then(function(result) {if (options.fundids) {
|
|
599
|
+
const result = await query;
|
|
600
|
+
|
|
601
|
+
if (options.fundids) {
|
|
611
602
|
_.each(result, function(lp) {
|
|
612
603
|
lp.transactions = _.filter(lp.transactions, function(transaction) {
|
|
613
604
|
return _.find(options.fundids, function(f) {
|
|
@@ -619,13 +610,11 @@ module.exports = function(mongoose, config) {
|
|
|
619
610
|
|
|
620
611
|
return cb(null, result);
|
|
621
612
|
|
|
622
|
-
}
|
|
613
|
+
} catch(err) { return cb(err); }
|
|
623
614
|
|
|
624
615
|
};
|
|
625
616
|
|
|
626
|
-
LimitedPartner.statics.listByFund = function (fundId, options, cb) {
|
|
627
|
-
|
|
628
|
-
const self = this;
|
|
617
|
+
LimitedPartner.statics.listByFund = async function (fundId, options, cb) {
|
|
629
618
|
|
|
630
619
|
if (!cb) { throw new Error('cb is required'); }
|
|
631
620
|
if (!fundId) { return cb(new Error('fundId is required'), null); }
|
|
@@ -636,15 +625,19 @@ module.exports = function(mongoose, config) {
|
|
|
636
625
|
|
|
637
626
|
options = helpers.getDefaultOptions(options);
|
|
638
627
|
|
|
639
|
-
|
|
628
|
+
try {
|
|
629
|
+
let query = this.find({ 'transactions.fund': fundId, customer: options.CUSTOMER_ID }, getReadFilterKeys(options.role));
|
|
630
|
+
|
|
631
|
+
query.populate('transactions.fund');
|
|
632
|
+
query.sort({ 'name': -1 });
|
|
640
633
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
634
|
+
const result = await query;
|
|
635
|
+
return cb(null, result);
|
|
636
|
+
} catch(err) { return cb(err); }
|
|
644
637
|
|
|
645
638
|
};
|
|
646
639
|
|
|
647
|
-
LimitedPartner.statics.modify = function(filter, update, cb) {
|
|
640
|
+
LimitedPartner.statics.modify = async function(filter, update, cb) {
|
|
648
641
|
|
|
649
642
|
// VERY IMPORTANT NOTE
|
|
650
643
|
// findByIdAndUpdate and findOneAndUpdate do not trigger pre-save hook so that code will not run here
|
|
@@ -654,17 +647,18 @@ module.exports = function(mongoose, config) {
|
|
|
654
647
|
if (!filter) { return cb(new Error('filter is required'), null); }
|
|
655
648
|
if (!update) { return cb(new Error('update is required'), null); }
|
|
656
649
|
|
|
657
|
-
var self = this;
|
|
658
|
-
|
|
659
650
|
// https://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate
|
|
660
651
|
// options runValidators defaults false which is ok since we have upsert false
|
|
661
652
|
// new returns the updated document
|
|
662
653
|
|
|
663
|
-
|
|
654
|
+
try {
|
|
655
|
+
const result = await this.findOneAndUpdate(filter, update, { upsert: false, new: true });
|
|
656
|
+
return cb(null, result);
|
|
657
|
+
} catch(err) { return cb(err); }
|
|
664
658
|
|
|
665
659
|
};
|
|
666
660
|
|
|
667
|
-
LimitedPartner.statics.modifyById = function(id, update, cb) {
|
|
661
|
+
LimitedPartner.statics.modifyById = async function(id, update, cb) {
|
|
668
662
|
|
|
669
663
|
// VERY IMPORTANT NOTE
|
|
670
664
|
// findByIdAndUpdate and findOneAndUpdate do not trigger pre-save hook so that code will not run here
|
|
@@ -675,73 +669,72 @@ module.exports = function(mongoose, config) {
|
|
|
675
669
|
if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
|
|
676
670
|
if (!update) { return cb(new Error('update is required'), null); }
|
|
677
671
|
|
|
678
|
-
var self = this;
|
|
679
|
-
|
|
680
672
|
// https://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate
|
|
681
673
|
// options runValidators defaults false which is ok since we have upsert false
|
|
682
674
|
// new returns the updated document
|
|
683
675
|
|
|
684
|
-
|
|
676
|
+
try {
|
|
677
|
+
const result = await this.findByIdAndUpdate(id, update, { upsert: false, new: true });
|
|
678
|
+
return cb(null, result);
|
|
679
|
+
} catch(err) { return cb(err); }
|
|
685
680
|
|
|
686
681
|
};
|
|
687
682
|
|
|
688
|
-
LimitedPartner.statics.removeCustomerTransactions = function removeCustomerTransactions(customerId, cb) {
|
|
689
|
-
|
|
690
|
-
const self = this;
|
|
683
|
+
LimitedPartner.statics.removeCustomerTransactions = async function removeCustomerTransactions(customerId, cb) {
|
|
691
684
|
|
|
692
685
|
if (!cb) { throw new Error('cb is required'); }
|
|
693
686
|
if (!customerId) { return cb(new Error('customerId is required'), null); }
|
|
694
687
|
if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
|
|
695
688
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
689
|
+
try {
|
|
690
|
+
let query = this.updateMany(
|
|
691
|
+
{ 'customer': customerId },
|
|
692
|
+
{ $set: { transactions: [] } }
|
|
693
|
+
);
|
|
701
694
|
|
|
702
|
-
|
|
695
|
+
const result = await query;
|
|
696
|
+
return cb(null, result);
|
|
697
|
+
} catch(err) { return cb(err); }
|
|
703
698
|
|
|
704
699
|
};
|
|
705
700
|
|
|
706
|
-
LimitedPartner.statics.removeCustomerTags = function removeCustomerTags(customerId, cb) {
|
|
707
|
-
|
|
708
|
-
const self = this;
|
|
701
|
+
LimitedPartner.statics.removeCustomerTags = async function removeCustomerTags(customerId, cb) {
|
|
709
702
|
|
|
710
703
|
if (!cb) { throw new Error('cb is required'); }
|
|
711
704
|
if (!customerId) { return cb(new Error('customerId is required'), null); }
|
|
712
705
|
if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
|
|
713
706
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
707
|
+
try {
|
|
708
|
+
let query = this.updateMany(
|
|
709
|
+
{ 'customer': customerId },
|
|
710
|
+
{ $set: { details: [] } }
|
|
711
|
+
);
|
|
719
712
|
|
|
720
|
-
|
|
713
|
+
const result = await query;
|
|
714
|
+
return cb(null, result);
|
|
715
|
+
} catch(err) { return cb(err); }
|
|
721
716
|
|
|
722
717
|
};
|
|
723
718
|
|
|
724
|
-
LimitedPartner.statics.removeCustomerPeople = function removeCustomerPeople(customerId, cb) {
|
|
725
|
-
|
|
726
|
-
const self = this;
|
|
719
|
+
LimitedPartner.statics.removeCustomerPeople = async function removeCustomerPeople(customerId, cb) {
|
|
727
720
|
|
|
728
721
|
if (!cb) { throw new Error('cb is required'); }
|
|
729
722
|
if (!customerId) { return cb(new Error('customerId is required'), null); }
|
|
730
723
|
if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
|
|
731
724
|
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
725
|
+
try {
|
|
726
|
+
let query = this.updateMany(
|
|
727
|
+
{ 'customer': customerId },
|
|
728
|
+
{ $set: { people: [] } }
|
|
729
|
+
);
|
|
737
730
|
|
|
738
|
-
|
|
731
|
+
const result = await query;
|
|
732
|
+
return cb(null, result);
|
|
733
|
+
} catch(err) { return cb(err); }
|
|
739
734
|
|
|
740
735
|
};
|
|
741
736
|
|
|
742
|
-
LimitedPartner.statics.search = function (terms, options, cb) {
|
|
743
|
-
|
|
744
|
-
const self = this;
|
|
737
|
+
LimitedPartner.statics.search = async function (terms, options, cb) {
|
|
745
738
|
|
|
746
739
|
if (!cb) { throw new Error('cb is required'); }
|
|
747
740
|
if (!terms) { return cb(new Error('terms is required'), null); }
|
|
@@ -751,26 +744,28 @@ module.exports = function(mongoose, config) {
|
|
|
751
744
|
|
|
752
745
|
options = helpers.getDefaultOptions(options);
|
|
753
746
|
|
|
754
|
-
let query;
|
|
755
|
-
|
|
756
747
|
if (options.role === 'none') { return cb(null, []); }
|
|
757
748
|
|
|
758
|
-
|
|
759
|
-
query
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
749
|
+
try {
|
|
750
|
+
let query;
|
|
751
|
+
|
|
752
|
+
if (options.isWorkerProcess) {
|
|
753
|
+
query = this.find({'name': new RegExp(terms, 'i')}, getReadFilterKeys(options.role));
|
|
754
|
+
}
|
|
755
|
+
else {
|
|
756
|
+
query = this.find({ 'name': new RegExp(terms, 'i'), customer: options.CUSTOMER_ID }, getReadFilterKeys(options.role));
|
|
757
|
+
}
|
|
764
758
|
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
|
|
759
|
+
query.populate('transactions.fund');
|
|
760
|
+
query.sort({ 'name': -1 });
|
|
768
761
|
|
|
769
|
-
|
|
762
|
+
const result = await query;
|
|
763
|
+
return cb(null, result);
|
|
764
|
+
} catch(err) { return cb(err); }
|
|
770
765
|
|
|
771
|
-
|
|
766
|
+
};
|
|
772
767
|
|
|
773
|
-
|
|
768
|
+
LimitedPartner.statics.search2 = async function search2(value, options, cb) {
|
|
774
769
|
|
|
775
770
|
if (!cb) { throw new Error('cb is required'); }
|
|
776
771
|
if (!value) { return cb(new Error('value is required'), null); }
|
|
@@ -787,51 +782,54 @@ module.exports = function(mongoose, config) {
|
|
|
787
782
|
// combine provided and default options
|
|
788
783
|
options = _.defaults(options || {}, defaultOptions);
|
|
789
784
|
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
785
|
+
try {
|
|
786
|
+
const result = await this.aggregate([
|
|
787
|
+
{
|
|
788
|
+
"$search": {
|
|
789
|
+
index: 'default',
|
|
790
|
+
compound: {
|
|
791
|
+
should: [
|
|
792
|
+
{
|
|
793
|
+
text: {
|
|
794
|
+
query: value,
|
|
795
|
+
path: [
|
|
796
|
+
'name',
|
|
797
|
+
'stakeholders',
|
|
798
|
+
'details.value'
|
|
799
|
+
],
|
|
800
|
+
fuzzy: {
|
|
801
|
+
maxEdits: options.maxEdits,
|
|
802
|
+
maxExpansions: options.maxExpansions
|
|
803
|
+
},
|
|
804
|
+
score: { boost: { value: 3 } }
|
|
805
|
+
}
|
|
809
806
|
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
807
|
+
],
|
|
808
|
+
must: [
|
|
809
|
+
{
|
|
810
|
+
equals: {
|
|
811
|
+
path: 'customer',
|
|
812
|
+
value: new mongoose.Types.ObjectId(options.CUSTOMER_ID)
|
|
813
|
+
}
|
|
817
814
|
}
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
815
|
+
],
|
|
816
|
+
minimumShouldMatch: 1
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
},
|
|
820
|
+
{
|
|
821
|
+
$limit: options.limit,
|
|
822
|
+
},
|
|
823
|
+
{
|
|
824
|
+
$project: {
|
|
825
|
+
name: 1,
|
|
826
|
+
transactions: 1,
|
|
827
|
+
score: { $meta: "searchScore" }
|
|
821
828
|
}
|
|
822
829
|
}
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
},
|
|
827
|
-
{
|
|
828
|
-
$project: {
|
|
829
|
-
name: 1,
|
|
830
|
-
transactions: 1,
|
|
831
|
-
score: { $meta: "searchScore" }
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
]).exec().then(function(result) {_.each(result, function(item) {
|
|
830
|
+
]);
|
|
831
|
+
|
|
832
|
+
_.each(result, function(item) {
|
|
835
833
|
item.commitment = calculateTotalCommitment(item.transactions);
|
|
836
834
|
item.contribution = calculateTotalContribution(item.transactions);
|
|
837
835
|
delete item.transactions;
|
|
@@ -839,12 +837,11 @@ module.exports = function(mongoose, config) {
|
|
|
839
837
|
|
|
840
838
|
return cb(null, result);
|
|
841
839
|
|
|
842
|
-
|
|
843
|
-
}).catch(function(err) { cb(err); });
|
|
840
|
+
} catch(err) { return cb(err); }
|
|
844
841
|
|
|
845
842
|
};
|
|
846
843
|
|
|
847
|
-
LimitedPartner.statics.upsert = function(lp, username, options, cb) {
|
|
844
|
+
LimitedPartner.statics.upsert = async function(lp, username, options, cb) {
|
|
848
845
|
|
|
849
846
|
if (!cb) { throw new Error('cb is required'); }
|
|
850
847
|
if (!lp) { return cb(new Error('lp is required'), null); }
|
|
@@ -860,7 +857,10 @@ module.exports = function(mongoose, config) {
|
|
|
860
857
|
lp.markModified('details');
|
|
861
858
|
lp.markModified('customFields');
|
|
862
859
|
|
|
863
|
-
|
|
860
|
+
try {
|
|
861
|
+
const result = await lp.save();
|
|
862
|
+
return cb(null, result);
|
|
863
|
+
} catch(err) { return cb(err); }
|
|
864
864
|
|
|
865
865
|
};
|
|
866
866
|
|