@dhyasama/totem-models 1.0.0 → 1.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/Account.js CHANGED
@@ -53,14 +53,6 @@ module.exports = function(mongoose, config) {
53
53
  required: true
54
54
  },
55
55
 
56
- // todo - change to org
57
- customer: {
58
- type: Schema.ObjectId,
59
- ref: 'Investor',
60
- required: false
61
- },
62
-
63
- // todo - port from customer
64
56
  org: {
65
57
  type: Schema.ObjectId,
66
58
  ref: 'Organization',
@@ -584,28 +584,6 @@ module.exports = function(mongoose, config) {
584
584
 
585
585
  };
586
586
 
587
- //TODO: this is same as Person & Portfolio Company Function
588
- //Helper function that multiple models can use...
589
- LimitedPartner.statics.verify = function(lpId, verified, username, role, cb) {
590
-
591
- this
592
- .findById(lpId, this.getReadFilterKeys(role))
593
- .exec(function(err, lp) {
594
-
595
- lp.status.verified = verified;
596
- lp.status.verifiedBy = username;
597
- lp.status.verifiedOn = Date.now();
598
-
599
- if(verified) {
600
- lp.flagged.resolved = true;
601
- }
602
-
603
- return this.upsert(lp, username, role, cb);
604
-
605
- });
606
-
607
- };
608
-
609
587
  LimitedPartner.statics.flag = function(lpId, resolved, text, username, role, cb) {
610
588
 
611
589
  var context = this;
@@ -685,24 +663,6 @@ module.exports = function(mongoose, config) {
685
663
  return next();
686
664
  });
687
665
 
688
- // var takeSnapshot = function(cb) {
689
- //
690
- // var LimitedPartnerHistory = mongoose.model('LimitedPartnerHistory');
691
- // var snapshot = new LimitedPartnerHistory();
692
- // snapshot.create(self, 'jason', function(err, result) {
693
- // if (err) {} // todo: alert admin to fix; ok to proceed;
694
- // return cb();
695
- // });
696
- //
697
- // };
698
- //
699
- // encryptSensitiveData(function() {
700
- // takeSnapshot(function() {
701
- // return next();
702
- // })
703
- // });
704
-
705
-
706
666
  });
707
667
 
708
668
  LimitedPartner.pre('init', function(next) {
package/lib/List.js CHANGED
@@ -24,13 +24,12 @@ module.exports = function(mongoose, config) {
24
24
 
25
25
  // Keeping these separate to facilitate population
26
26
 
27
- // todo - how to update these with company consolidation?
28
-
29
27
  limitedPartners: [{ type: Schema.ObjectId, ref: 'LimitedPartner', index: false, required: false }],
30
28
 
31
29
  organizations: [{ type: Schema.ObjectId, ref: 'Organization', index: false, required: false }],
32
30
 
33
31
  people: [{ type: Schema.ObjectId, ref: 'Person', index: false, required: false }]
32
+
34
33
  });
35
34
 
36
35
  // Items are kept separate to facilitate population
package/lib/News.js CHANGED
@@ -22,24 +22,6 @@ module.exports = function(mongoose, config) {
22
22
 
23
23
  publication: { type: String },
24
24
 
25
- fundsInvolved: [{
26
- type: Schema.ObjectId,
27
- ref: 'Fund'
28
- }],
29
-
30
- // TODO - make all news about port cos
31
- // required: true
32
- // remove internal
33
- // update admin to reflect these changes
34
-
35
- // todo - put new org id in org field
36
- portfolioCompany: {
37
- type: Schema.ObjectId,
38
- ref: 'PortfolioCompany',
39
- required: false,
40
- default: null
41
- },
42
-
43
25
  org: {
44
26
  type: Schema.ObjectId,
45
27
  ref: 'Organization',
@@ -49,13 +31,6 @@ module.exports = function(mongoose, config) {
49
31
 
50
32
  internal: { type: Boolean, default: false },
51
33
 
52
- // TODO - this will be going away
53
- discourse: {
54
- id: { type: String },
55
- firstPostId: { type: String },
56
- slug: { type: String }
57
- },
58
-
59
34
  extracted: { type: Schema.Types.Mixed }
60
35
 
61
36
  });
@@ -64,7 +39,7 @@ module.exports = function(mongoose, config) {
64
39
 
65
40
  this
66
41
  .findById(id)
67
- .populate('org fundsInvolved')
42
+ .populate('org')
68
43
  .exec(cb);
69
44
 
70
45
  };
@@ -73,7 +48,7 @@ module.exports = function(mongoose, config) {
73
48
 
74
49
  this
75
50
  .find()
76
- .populate('org fundsInvolved')
51
+ .populate('org')
77
52
  .sort('-createdOn')
78
53
  .exec(cb);
79
54
 
@@ -83,7 +58,7 @@ module.exports = function(mongoose, config) {
83
58
 
84
59
  this
85
60
  .find({ org: id })
86
- .populate('org fundsInvolved')
61
+ .populate('org')
87
62
  .sort('-createdOn')
88
63
  .exec(cb);
89
64
 
@@ -93,7 +68,7 @@ module.exports = function(mongoose, config) {
93
68
 
94
69
  this
95
70
  .find()
96
- .populate('org fundsInvolved')
71
+ .populate('org')
97
72
  .sort('-createdOn')
98
73
  .exec(function (err, news) {
99
74
 
@@ -109,38 +84,6 @@ module.exports = function(mongoose, config) {
109
84
 
110
85
  };
111
86
 
112
- News.statics.listInternal = function (cb) {
113
-
114
- this
115
- .find({ internal: true })
116
- .populate('org fundsInvolved')
117
- .sort('-createdOn')
118
- .exec(cb);
119
-
120
- };
121
-
122
- News.statics.listForFunds = function (fundIds, cb) {
123
-
124
- if (!fundIds || fundIds.length == 0) return cb(null, null);
125
-
126
- this
127
- .find({ fundsInvolved: { $in : fundIds } })
128
- .populate('org fundsInvolved')
129
- .sort('-createdOn')
130
- .exec(function(err, result) {
131
-
132
- if (err) return cb(err, null);
133
-
134
- _.each(result, function(newsItem) {
135
- newsItem.fundsInvolved = _.filter(newsItem.fundsInvolved, function(fund) { return fundIds.indexOf(fund._id.toString()) >= 0; });
136
- });
137
-
138
- return cb(null, result);
139
-
140
- });
141
-
142
- };
143
-
144
87
  News.statics.upsert = function (news, cb) {
145
88
  news.markModified('extracted');
146
89
  news.save(cb);
@@ -182,7 +182,7 @@ module.exports = function(mongoose, config) {
182
182
  fullyDiluted: { type: Number, default: 0 },
183
183
  asOfDate: { type: Date },
184
184
 
185
- // todo - ???
185
+ // todo - ??? - clarify how to handle this
186
186
  optionsAndWarrants: {
187
187
  unissued: { type: Number },
188
188
  issuedToUnspecified: { type: Number }
@@ -338,54 +338,6 @@ module.exports = function(mongoose, config) {
338
338
 
339
339
  };
340
340
 
341
- // todo - what are "basic" fields and how are they used?
342
- Organization.methods.newBasic = function(field, value) {
343
-
344
- var compoundField = false;
345
- if(field.split(".").length > 1) {
346
- compoundField = true;
347
- }
348
-
349
- if(!compoundField) {
350
- this[field] = value;
351
- } else {
352
- var parentField = field.split('.')[0];
353
- var childField = field.split('.')[1];
354
-
355
- this[parentField][childField] = value;
356
- }
357
-
358
- };
359
-
360
- Organization.methods.updateBasic = function(field, value) {
361
-
362
- var compoundField = false;
363
- if(field.split(".").length > 1) {
364
- compoundField = true;
365
- }
366
-
367
- if(!compoundField) {
368
- var currentVal = this[field];
369
- this[field] = value;
370
- } else {
371
- var parentField = field.split('.')[0];
372
- var childField = field.split('.')[1];
373
-
374
- var currentVal = this[parentField][childField];
375
- this[parentField][childField] = value;
376
- }
377
-
378
- };
379
-
380
- Organization.methods.updateContact = function(field, value) {
381
-
382
- var parentField = field.split('.')[0];
383
- var childField = field.split('.')[1];
384
-
385
- this[parentField][childField] = value;
386
-
387
- };
388
-
389
341
  Organization.methods.addPerson = function(personToAdd) {
390
342
 
391
343
  var self = this;
@@ -415,125 +367,6 @@ module.exports = function(mongoose, config) {
415
367
 
416
368
  };
417
369
 
418
- Organization.methods.updateFunds = function(funds) {
419
-
420
- var self = this;
421
-
422
- // todo - ??? - funds invested into this org or funds this org invests from?
423
-
424
- if (!self.portfolioCompany) return;
425
-
426
- // wipe funds and start fresh
427
- self.portfolioCompany.fundsInvested = funds;
428
-
429
- // Checking if it's a valid object id is a shortcut
430
- // TODO: The alternative is to get a list of funds and verify against that
431
- // TODO: also would be good to check for dupes
432
- // This is used internally, in admin, so let's punt for now
433
-
434
- //_.each(fundIds, function(fundId) {
435
- // if (utilities.isValidObjectId(fundId.id)) {
436
- // self.fundsInvested.push(fundId);
437
- // };
438
- //});
439
-
440
- };
441
-
442
- Organization.methods.updateChair = function(chairObj) {
443
-
444
- var self = this;
445
-
446
- if (!self.portfolioCompany) return;
447
-
448
- // todo - needs customer id
449
-
450
- switch(chairObj.num) {
451
- case 'chair1':
452
- if(chairObj.val && chairObj.val != "") {
453
- self.portfolioCompany.chairs.first = chairObj.val;
454
- } else {
455
- self.portfolioCompany.chairs.first = {};
456
- }
457
- break;
458
-
459
- case 'chair2':
460
- if(chairObj.val && chairObj.val != "") {
461
- self.portfolioCompany.chairs.second = chairObj.val;
462
- } else {
463
- self.portfolioCompany.chairs.second = {}
464
- }
465
- break;
466
- }
467
-
468
- };
469
-
470
- // todo - change this to exit (with acquisition or ipo)
471
- Organization.methods.updateAcquisition = function(aObj) {
472
-
473
- var self = this;
474
-
475
- if (!self.portfolioCompany) return;
476
-
477
- self.portfolioCompany.acquisition = aObj;
478
-
479
- };
480
-
481
- Organization.methods.removeInvestmentsAndDebtsByCustomer = function(investor) {
482
-
483
- var self = this;
484
-
485
- // todo - change to round.funds and capTable.customer
486
-
487
- if (!self.portfolioCompany) return;
488
-
489
- if(self.portfolioCompany.investments.length > 0) {
490
- self.portfolioCompany.investments = _.reject(self.portfolioCompany.investments, function(i) {
491
- return String(i.source) == String(investor._id);
492
- });
493
- }
494
-
495
- if(self.portfolioCompany.debts.length > 0) {
496
- self.portfolioCompany.debts = _.reject(self.portfolioCompany.debts, function(d) {
497
- return String(d.source) == String(investor._id);
498
- });
499
- }
500
-
501
- if(self.portfolioCompany.fundsInvested.length > 0) {
502
- self.portfolioCompany.fundsInvested = _.reject(self.portfolioCompany.fundsInvested, function(f) {
503
- return String(f.investor._id || f.investor) == String(investor._id);
504
- });
505
- }
506
-
507
- };
508
-
509
- Organization.methods.addCompanyToInvestor = function(idOfCompanyToAdd) {
510
-
511
- var self = this;
512
- if (!self.investor) return;
513
-
514
- var match = _.find(self.investor.companies, function(company) {
515
- var companyId = utils.isValidObjectId(company) ? company : company.id;
516
- return companyId.toString() == idOfCompanyToAdd.toString();
517
- });
518
-
519
- if (!match) self.investor.companies.push(idOfCompanyToAdd);
520
-
521
- };
522
-
523
- Organization.methods.addFundToInvestor = function(idOfFundToAdd) {
524
-
525
- var self = this;
526
- if (!self.investor) return;
527
-
528
- var match = _.find(self.investor.funds, function(fund) {
529
- var fundId = utils.isValidObjectId(fund) ? fund : fund.id;
530
- return fundId.toString() == idOfFundToAdd.toString();
531
- });
532
-
533
- if (!match) self.investor.funds.push(idOfFundToAdd);
534
-
535
- };
536
-
537
370
  ///////////////////////
538
371
 
539
372
  // search for orgs based on fields provided
@@ -715,11 +548,12 @@ module.exports = function(mongoose, config) {
715
548
  };
716
549
 
717
550
  Organization.statics.findByPerson = function findByPerson(personId, cb) {
551
+ // Given a person id, get all organizations with that person
718
552
  this.find({ 'people.person': personId, 'deleted': {$ne: true} }).exec(cb);
719
553
  };
720
554
 
721
555
  Organization.statics.findBySlug = function findBySlug(slug, cb) {
722
- this.find({ slug: slug, 'deleted': {$ne: true} }).exec(cb);
556
+ this.findOne({ slug: slug, 'deleted': {$ne: true} }).exec(cb);
723
557
  };
724
558
 
725
559
  Organization.statics.findBySlugs = function findBySlugs(slugs, cb) {
@@ -801,6 +635,8 @@ module.exports = function(mongoose, config) {
801
635
 
802
636
  Organization.statics.getPortfolio = function getPortfolio(orgId, cb) {
803
637
 
638
+ // Get all organizations invested in by the given org id
639
+
804
640
  var self = this;
805
641
 
806
642
  self
@@ -930,7 +766,8 @@ module.exports = function(mongoose, config) {
930
766
 
931
767
  Organization.post('init', function() {
932
768
 
933
- // Protect private data and merge public and private data
769
+ // Protect private data
770
+ // Merge public and private data
934
771
 
935
772
  var self = this;
936
773
  var CUSTOMER_ID = config.CUSTOMER_ID;
package/lib/Person.js CHANGED
@@ -787,27 +787,6 @@ module.exports = function(mongoose, config) {
787
787
  .exec(cb);
788
788
  };
789
789
 
790
- // TODO - make dynamic
791
- Person.statics.getPartners = function (cb) {
792
-
793
- var partnerEmails = [
794
- 'john@ffvc.com',
795
- 'adam@ffvc.com',
796
- 'alex@ffvc.com',
797
- 'david@ffvc.com',
798
- 'michael@ffvc.com',
799
- 'ryan@ffvc.com',
800
- 'herb@ffvc.com',
801
- 'paul@ffvc.com'
802
- ];
803
-
804
- this
805
- .find({ 'contact.email.email': { $in: partnerEmails }, 'deleted': { $ne: true } } )
806
- .populate('account boards.company chairs.first.company chairs.second.company')
807
- .exec(cb);
808
-
809
- };
810
-
811
790
  Person.statics.findByProviderEventId = function (id, cb) {
812
791
  this
813
792
  .find({ 'calendarEventSummaries.providerEventId': id })
@@ -829,7 +808,8 @@ module.exports = function(mongoose, config) {
829
808
  Person.statics.findByUniqueInfo = function (email, cb) {
830
809
 
831
810
  // useful for not inserting dupes
832
- // todo: expand this to check other fields
811
+ // could expand this to check other fields
812
+ // but really should be replaced by search
833
813
 
834
814
  this.findOne({
835
815
  $or: [
@@ -1042,16 +1022,6 @@ module.exports = function(mongoose, config) {
1042
1022
 
1043
1023
  ///////////////
1044
1024
 
1045
- // Person.pre('save', function(next) {
1046
- // var self = this;
1047
- // var PersonHistory = mongoose.model('PersonHistory');
1048
- // var snapshot = new PersonHistory();
1049
- // snapshot.create(self, 'jason', function(err, result) {
1050
- // if (err) {} // todo: alert admin to fix; ok to proceed;
1051
- // return next();
1052
- // });
1053
- // });
1054
-
1055
1025
  Person.post('remove', function(doc) {
1056
1026
  // Account.person
1057
1027
  // Investor.people
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "none",
6
6
  "description": "Models for Totem platform",
package/test/News.js CHANGED
@@ -31,16 +31,11 @@ describe('News', function() {
31
31
  news.createdOn = Date.now();
32
32
  news.title = 'Google';
33
33
  news.link = 'http://google.com';
34
- news.fundsInvolved.push(fund._id);
35
34
  news.internal = false;
36
- news.discourse.id = '1';
37
- news.discourse.slug = 'google';
38
- news.discourse.firstPostId = '1';
39
35
 
40
36
  News.upsert(news, function(err, item) {
41
37
  should.not.exist(err);
42
38
  should.exist(item);
43
- item.fundsInvolved.length.should.equal(1);
44
39
  news = item;
45
40
  done();
46
41
  });
@@ -60,50 +55,29 @@ describe('News', function() {
60
55
 
61
56
  });
62
57
 
63
- it('gets a news item by id', function(done) {
64
- News.getById(news.id, function(err, item) {
65
- should.not.exist(err);
66
- should.exist(item);
67
- item.id.should.equal(news.id);
68
- done();
69
- });
70
- });
71
-
72
- it('lists all news items', function(done) {
73
- News.list(function(err, items) {
74
- should.not.exist(err);
75
- should.exist(items);
76
- items.length.should.equal(1);
77
- done();
78
- });
79
- });
80
-
81
- it('lists news items for a fund', function(done) {
82
- News.listForFunds([fund._id], function(err, items) {
83
- should.not.exist(err);
84
- should.exist(items);
85
- items.length.should.equal(1);
86
- done();
87
- });
58
+ it('gets a news item by id', function(done) {
59
+ News.getById(news.id, function(err, item) {
60
+ should.not.exist(err);
61
+ should.exist(item);
62
+ item.id.should.equal(news.id);
63
+ done();
64
+ });
88
65
  });
89
66
 
90
-
91
- it('lists news items for funds', function(done) {
92
- News.listForFunds([fund._id, new mongoose.Types.ObjectId()], function(err, items) {
93
- should.not.exist(err);
94
- should.exist(items);
95
- items.length.should.equal(1);
96
- done();
97
- });
67
+ it('lists all news items', function(done) {
68
+ News.list(function(err, items) {
69
+ should.not.exist(err);
70
+ should.exist(items);
71
+ items.length.should.equal(1);
72
+ done();
73
+ });
98
74
  });
99
75
 
100
- it('deletes a news item', function(done) {
101
- News.delete(news.id, function(err, item) {
102
- should.not.exist(err);
103
- done();
104
- });
105
- });
106
-
107
- // todo - listforcompany
76
+ it('deletes a news item', function(done) {
77
+ News.delete(news.id, function(err, item) {
78
+ should.not.exist(err);
79
+ done();
80
+ });
81
+ });
108
82
 
109
83
  });
@@ -262,32 +262,6 @@ describe('Organization', function() {
262
262
  });
263
263
  }); // end adds an org
264
264
 
265
- it('adds a basic field to org', function(done) {
266
-
267
- org1.newBasic('slug', 'org1-slug');
268
-
269
- Organization.upsert(org1, 'test-user', function(err, org) {
270
- should.not.exist(err);
271
- should.exist(org);
272
- org.slug.should.equal('org1-slug');
273
- org1 = org;
274
- done();
275
- });
276
- }); // end adds a basic field
277
-
278
- it('updates a basic field on org', function(done) {
279
-
280
- org1.updateBasic('website', 'updatedorg1.com');
281
-
282
- Organization.upsert(org1, 'test-user', function(err, org) {
283
- should.not.exist(err);
284
- should.exist(org);
285
- org.website.should.equal('updatedorg1.com');
286
- org1 = org;
287
- done();
288
- });
289
- }); // end update a basic field
290
-
291
265
  it('finds a fuzzy match by name', function(done) {
292
266
 
293
267
  Organization.search({
@@ -436,7 +410,6 @@ describe('Organization', function() {
436
410
  Organization.findBySlug('org2-slug', function(err, org) {
437
411
  should.not.exist(err);
438
412
  should.exist(org);
439
- org.length.should.equal(1);
440
413
  done();
441
414
  });
442
415
 
@@ -444,7 +417,7 @@ describe('Organization', function() {
444
417
 
445
418
  it('finds org by slugs', function(done) {
446
419
 
447
- Organization.findBySlugs(['org1-slug', 'org2-slug'], function(err, orgs) {
420
+ Organization.findBySlugs(['fudge-3', 'org2-slug'], function(err, orgs) {
448
421
  should.not.exist(err);
449
422
  should.exist(orgs);
450
423
  orgs.length.should.equal(2);