@dhyasama/totem-models 1.22.3 → 1.23.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/LimitedPartner.js +41 -16
- package/lib/Organization.js +66 -54
- package/package.json +1 -1
- package/test/Organization.js +114 -0
package/lib/LimitedPartner.js
CHANGED
|
@@ -19,8 +19,8 @@ module.exports = function(mongoose, config) {
|
|
|
19
19
|
async = require('async'),
|
|
20
20
|
utils = require('@dhyasama/ffvc-utilities');
|
|
21
21
|
|
|
22
|
-
var
|
|
23
|
-
Organization.getById(
|
|
22
|
+
var getFundIdsForOrg = function(id, cb) {
|
|
23
|
+
Organization.getById(id, function(err, org) {
|
|
24
24
|
if (err) return cb(err, null);
|
|
25
25
|
else if (!org) return cb(null, null);
|
|
26
26
|
var fundIds = _.map(org.funds, function(fund) {
|
|
@@ -36,6 +36,8 @@ module.exports = function(mongoose, config) {
|
|
|
36
36
|
|
|
37
37
|
shortName: { type: String, default: '' },
|
|
38
38
|
|
|
39
|
+
customer: { type: Schema.ObjectId, ref: 'Organization' },
|
|
40
|
+
|
|
39
41
|
start: { type: String, default: '' },
|
|
40
42
|
|
|
41
43
|
people: [{
|
|
@@ -400,7 +402,7 @@ module.exports = function(mongoose, config) {
|
|
|
400
402
|
getLp();
|
|
401
403
|
}
|
|
402
404
|
else {
|
|
403
|
-
|
|
405
|
+
getFundIdsForOrg(CUSTOMER_ID, function(err, fundIds) {
|
|
404
406
|
if (err) return cb(err, null);
|
|
405
407
|
query = self.findOne({ '_id': id, 'fundsInvested.fund': { $in : fundIds }}, self.getReadFilterKeys(role));
|
|
406
408
|
getLp();
|
|
@@ -429,19 +431,13 @@ module.exports = function(mongoose, config) {
|
|
|
429
431
|
getLps(query);
|
|
430
432
|
}
|
|
431
433
|
else {
|
|
432
|
-
|
|
434
|
+
getFundIdsForOrg(CUSTOMER_ID, function(err, fundIds) {
|
|
433
435
|
if (err) return cb(err, null);
|
|
434
436
|
query = self.find({'people': personId, 'fundsInvested.fund': { $in : fundIds }}, self.getReadFilterKeys(role));
|
|
435
437
|
getLps(query);
|
|
436
438
|
});
|
|
437
439
|
}
|
|
438
440
|
|
|
439
|
-
// self
|
|
440
|
-
// .find({'people': personId}, this.getReadFilterKeys(role))
|
|
441
|
-
// .populate('fundsInvested.fund')
|
|
442
|
-
// .populate('people', 'name')
|
|
443
|
-
// .exec(cb);
|
|
444
|
-
|
|
445
441
|
};
|
|
446
442
|
|
|
447
443
|
LimitedPartner.statics.getFlags = function getFlags(lpid, cb) {
|
|
@@ -514,7 +510,7 @@ module.exports = function(mongoose, config) {
|
|
|
514
510
|
getLps(query);
|
|
515
511
|
}
|
|
516
512
|
else {
|
|
517
|
-
|
|
513
|
+
getFundIdsForOrg(CUSTOMER_ID, function(err, fundIds) {
|
|
518
514
|
if (err) return cb(err, null);
|
|
519
515
|
query = self.find({ 'fundsInvested.fund': { $in : fundIds }}, self.getReadFilterKeys(role));
|
|
520
516
|
getLps(query);
|
|
@@ -523,6 +519,31 @@ module.exports = function(mongoose, config) {
|
|
|
523
519
|
|
|
524
520
|
};
|
|
525
521
|
|
|
522
|
+
LimitedPartner.statics.listForOrganization = function (orgid, role, cb) {
|
|
523
|
+
|
|
524
|
+
// sorted by name ascending
|
|
525
|
+
// sort is done post retrieval because query sort is done pre-decryption
|
|
526
|
+
|
|
527
|
+
var self = this;
|
|
528
|
+
var query;
|
|
529
|
+
|
|
530
|
+
var getLps = function(q) {
|
|
531
|
+
q.populate('fundsInvested.fund')
|
|
532
|
+
q.exec(function (err, lps) {
|
|
533
|
+
if (err) return cb(err, null);
|
|
534
|
+
lps = _.sortBy(lps, function(lp) { return lp.name ? lp.name.toLowerCase() : ''; });
|
|
535
|
+
return cb(null, lps);
|
|
536
|
+
});
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
getFundIdsForOrg(orgid, function(err, fundIds) {
|
|
540
|
+
if (err) return cb(err, null);
|
|
541
|
+
query = self.find({ 'fundsInvested.fund': { $in : fundIds }}, self.getReadFilterKeys(role));
|
|
542
|
+
getLps(query);
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
};
|
|
546
|
+
|
|
526
547
|
LimitedPartner.statics.listAllUnverifiedLps = function (role, cb) {
|
|
527
548
|
|
|
528
549
|
if (role != 'admin') return cb(new Error('Unauthorized'), []);
|
|
@@ -617,7 +638,7 @@ module.exports = function(mongoose, config) {
|
|
|
617
638
|
getLps();
|
|
618
639
|
}
|
|
619
640
|
else {
|
|
620
|
-
|
|
641
|
+
getFundIdsForOrg(CUSTOMER_ID, function(err, fundIds) {
|
|
621
642
|
if (err) return cb(err, null);
|
|
622
643
|
query = self.find({ 'name': new RegExp(terms, "i"), 'fundsInvested.fund': { $in : fundIds }}, self.getReadFilterKeys(role));
|
|
623
644
|
getLps();
|
|
@@ -643,6 +664,7 @@ module.exports = function(mongoose, config) {
|
|
|
643
664
|
|
|
644
665
|
};
|
|
645
666
|
|
|
667
|
+
// Deprecated
|
|
646
668
|
LimitedPartner.statics.flag = function(lpId, resolved, text, username, role, cb) {
|
|
647
669
|
|
|
648
670
|
var context = this;
|
|
@@ -762,12 +784,16 @@ module.exports = function(mongoose, config) {
|
|
|
762
784
|
LimitedPartner.post('init', function(doc, next) {
|
|
763
785
|
|
|
764
786
|
if (CUSTOMER_ID != 'GLOBAL_PROCESS' && !LPS_ENABLED) {
|
|
765
|
-
|
|
766
|
-
return
|
|
787
|
+
|
|
788
|
+
// Don't return doc if lps aren't enabled or lp doesn't belong to current customer
|
|
789
|
+
if (!LPS_ENABLED || doc.customer != CUSTOMER_ID) {
|
|
790
|
+
doc = null;
|
|
791
|
+
return next();
|
|
792
|
+
}
|
|
793
|
+
|
|
767
794
|
}
|
|
768
795
|
|
|
769
796
|
// Decrypt sensitive data
|
|
770
|
-
|
|
771
797
|
if (this.distributions && this.distributions.ach) {
|
|
772
798
|
if (this.distributions.ach.accountType) {
|
|
773
799
|
this.distributions.ach.accountType = crypto.decrypt(this.distributions.ach.accountType);
|
|
@@ -794,7 +820,6 @@ module.exports = function(mongoose, config) {
|
|
|
794
820
|
this.distributions.ach.bankAccount.accountNumber = crypto.decrypt(this.distributions.ach.bankAccount.accountNumber);
|
|
795
821
|
}
|
|
796
822
|
}
|
|
797
|
-
|
|
798
823
|
if (this.k1 && this.k1.EIN) { this.k1.EIN = crypto.decrypt(this.k1.EIN); }
|
|
799
824
|
|
|
800
825
|
next();
|
package/lib/Organization.js
CHANGED
|
@@ -785,7 +785,10 @@ module.exports = function(mongoose, config) {
|
|
|
785
785
|
.populate('funds', 'name hexColorCode closeDate')
|
|
786
786
|
.populate('operating.acquired.public.by', 'name logoUrl')
|
|
787
787
|
.populate('operating.acquired.private.by', 'name logoUrl')
|
|
788
|
-
.populate(
|
|
788
|
+
.populate({
|
|
789
|
+
path: 'lps',
|
|
790
|
+
match: { customer: config.CUSTOMER_ID }
|
|
791
|
+
})
|
|
789
792
|
.deepPopulate([
|
|
790
793
|
'people.person.sources.person',
|
|
791
794
|
'people.person.calendarEventSummaries.attendees.internal',
|
|
@@ -941,7 +944,7 @@ module.exports = function(mongoose, config) {
|
|
|
941
944
|
|
|
942
945
|
};
|
|
943
946
|
|
|
944
|
-
Organization.statics.listCustomers = function
|
|
947
|
+
Organization.statics.listCustomers = function listCustomers(cb) {
|
|
945
948
|
|
|
946
949
|
var self = this;
|
|
947
950
|
|
|
@@ -1162,58 +1165,80 @@ module.exports = function(mongoose, config) {
|
|
|
1162
1165
|
|
|
1163
1166
|
var self = this;
|
|
1164
1167
|
|
|
1165
|
-
var
|
|
1168
|
+
var cleanContactInfo = function cleanContactInfo() {
|
|
1166
1169
|
|
|
1167
|
-
var
|
|
1170
|
+
var thereCanOnlyBeOne = function thereCanOnlyBeOne(items) {
|
|
1168
1171
|
|
|
1169
|
-
|
|
1172
|
+
var primaryItems = _.filter(items, function(item) { return item.primary; });
|
|
1170
1173
|
|
|
1171
|
-
|
|
1172
|
-
// skip the first one (leave it primary) and mark the rest as not primary
|
|
1173
|
-
if (index >= 1) item.primary = false;
|
|
1174
|
-
});
|
|
1174
|
+
if (primaryItems.length > 1) {
|
|
1175
1175
|
|
|
1176
|
-
|
|
1176
|
+
_.each(primaryItems, function(item, index) {
|
|
1177
|
+
// skip the first one (leave it primary) and mark the rest as not primary
|
|
1178
|
+
if (index >= 1) item.primary = false;
|
|
1179
|
+
});
|
|
1177
1180
|
|
|
1178
|
-
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
return items;
|
|
1184
|
+
|
|
1185
|
+
};
|
|
1186
|
+
|
|
1187
|
+
// must have something meaningful
|
|
1188
|
+
self.contact.address = _.map(self.contact.address, function(address) {
|
|
1189
|
+
if (!address.city && !address.state && !address.country) return null;
|
|
1190
|
+
else return address;
|
|
1191
|
+
});
|
|
1192
|
+
|
|
1193
|
+
self.contact.email = _.map(self.contact.email, function(item) {
|
|
1194
|
+
if (!item.email) return null;
|
|
1195
|
+
else return item;
|
|
1196
|
+
});
|
|
1197
|
+
|
|
1198
|
+
self.contact.phone = _.map(self.contact.phone, function(item) {
|
|
1199
|
+
if (!item.number) return null;
|
|
1200
|
+
else return item;
|
|
1201
|
+
});
|
|
1202
|
+
|
|
1203
|
+
// remove emptiness and dedupe
|
|
1204
|
+
self.contact.address = _.uniq(_.compact(self.contact.address), function(item) { return item.city + item.state + item.country; });
|
|
1205
|
+
self.contact.email = _.uniq(_.compact(self.contact.email), function(item) { return item.email; });
|
|
1206
|
+
self.contact.phone = _.uniq(_.compact(self.contact.phone), function(item) { return item.number; });
|
|
1207
|
+
|
|
1208
|
+
// only one primary
|
|
1209
|
+
self.contact.address = thereCanOnlyBeOne(self.contact.address);
|
|
1210
|
+
self.contact.email = thereCanOnlyBeOne(self.contact.email);
|
|
1211
|
+
self.contact.phone = thereCanOnlyBeOne(self.contact.phone);
|
|
1179
1212
|
|
|
1180
1213
|
};
|
|
1181
1214
|
|
|
1182
|
-
|
|
1183
|
-
self.contact.address = _.map(self.contact.address, function(address) {
|
|
1184
|
-
if (!address.city && !address.state && !address.country) return null;
|
|
1185
|
-
else return address;
|
|
1186
|
-
});
|
|
1215
|
+
var cleanPeople = function cleanPeople() {
|
|
1187
1216
|
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
else return item;
|
|
1191
|
-
});
|
|
1217
|
+
// remove junk
|
|
1218
|
+
self.people = _.reject(self.people, function(p) { return p.person == null; });
|
|
1192
1219
|
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
else return item;
|
|
1196
|
-
});
|
|
1220
|
+
// dedupe
|
|
1221
|
+
self.people = _.uniq(self.people, function(p) { return p.person._id ? p.person._id : p.person; });
|
|
1197
1222
|
|
|
1198
|
-
|
|
1199
|
-
self.contact.address = _.uniq(_.compact(self.contact.address), function(item) { return item.city + item.state + item.country; });
|
|
1200
|
-
self.contact.email = _.uniq(_.compact(self.contact.email), function(item) { return item.email; });
|
|
1201
|
-
self.contact.phone = _.uniq(_.compact(self.contact.phone), function(item) { return item.number; });
|
|
1223
|
+
};
|
|
1202
1224
|
|
|
1203
|
-
|
|
1204
|
-
self.contact.address = thereCanOnlyBeOne(self.contact.address);
|
|
1205
|
-
self.contact.email = thereCanOnlyBeOne(self.contact.email);
|
|
1206
|
-
self.contact.phone = thereCanOnlyBeOne(self.contact.phone);
|
|
1225
|
+
var cleanWebsites = function cleanWebsites() {
|
|
1207
1226
|
|
|
1208
|
-
|
|
1209
|
-
|
|
1227
|
+
// Format website
|
|
1228
|
+
if (self.website) self.website = utils.getDomain(self.website);
|
|
1210
1229
|
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1230
|
+
// Format website aliases
|
|
1231
|
+
if (self.websiteAliases && self.websiteAliases.length >= 1) {
|
|
1232
|
+
self.websiteAliases = _.map(self.websiteAliases, function(alias) {
|
|
1233
|
+
return utils.getDomain(alias);
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
};
|
|
1238
|
+
|
|
1239
|
+
cleanContactInfo();
|
|
1240
|
+
cleanPeople();
|
|
1241
|
+
cleanWebsites();
|
|
1217
1242
|
|
|
1218
1243
|
return next();
|
|
1219
1244
|
|
|
@@ -1231,6 +1256,7 @@ module.exports = function(mongoose, config) {
|
|
|
1231
1256
|
// remove customer details if not viewing self
|
|
1232
1257
|
if (doc._id.toString() != CUSTOMER_ID) doc.customer = {};
|
|
1233
1258
|
|
|
1259
|
+
doc.lps = _.reject(doc.lps, function(item) { return !item.customer || item.customer.toString() != CUSTOMER_ID; });
|
|
1234
1260
|
doc.filters = _.reject(doc.filters, function(item) { return !item.customer || item.customer.toString() != CUSTOMER_ID; });
|
|
1235
1261
|
doc.docs = _.reject(doc.docs, function(item) { return !item.customer || item.customer.toString() != CUSTOMER_ID; });
|
|
1236
1262
|
doc.iLevel = _.reject(doc.iLevel, function(item) { return !item.customer || item.customer.toString() != CUSTOMER_ID; });
|
|
@@ -1250,20 +1276,6 @@ module.exports = function(mongoose, config) {
|
|
|
1250
1276
|
|
|
1251
1277
|
});
|
|
1252
1278
|
|
|
1253
|
-
// var customerFunds = doc.constructor.customerFunds;
|
|
1254
|
-
// //console.log('customerFunds', customerFunds);
|
|
1255
|
-
// doc.lps = _.filter(doc.lps, function(lp) {
|
|
1256
|
-
// var lpFunds = _.pluck(lp.fundsInvested, 'fund');
|
|
1257
|
-
// var intersection = _.intersection(lpFunds, customerFunds);
|
|
1258
|
-
// return intersection.length >= 1;
|
|
1259
|
-
// });
|
|
1260
|
-
|
|
1261
|
-
// will there ever be a reason to show an org's lps?
|
|
1262
|
-
// a customer should only be able to see their own lps, which are queried and viewable on /lps
|
|
1263
|
-
// and if it's not used, why is it here?
|
|
1264
|
-
// todo - research flipping ref onto lp model
|
|
1265
|
-
doc.lps = [];
|
|
1266
|
-
|
|
1267
1279
|
return next();
|
|
1268
1280
|
|
|
1269
1281
|
});
|
package/package.json
CHANGED
package/test/Organization.js
CHANGED
|
@@ -9,12 +9,16 @@ var
|
|
|
9
9
|
clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
|
|
10
10
|
Organization = mongoose.model('Organization'),
|
|
11
11
|
Person = mongoose.model('Person'),
|
|
12
|
+
LimitedPartner = mongoose.model('LimitedPartner'),
|
|
13
|
+
Fund = mongoose.model('Fund'),
|
|
12
14
|
Note = mongoose.model('Note');
|
|
13
15
|
|
|
14
16
|
var person, person1, person2;
|
|
15
17
|
var noteId;
|
|
16
18
|
var eventNote;
|
|
17
19
|
var flagId;
|
|
20
|
+
var someOtherFund;
|
|
21
|
+
var someOtherLp;
|
|
18
22
|
|
|
19
23
|
describe('Organization', function() {
|
|
20
24
|
|
|
@@ -48,6 +52,15 @@ describe('Organization', function() {
|
|
|
48
52
|
});
|
|
49
53
|
});
|
|
50
54
|
|
|
55
|
+
before(function (done) {
|
|
56
|
+
Fund.collection.dropIndexes(function (err, result) {
|
|
57
|
+
should.not.exist(err);
|
|
58
|
+
should.exist(result);
|
|
59
|
+
result.should.equal(true);
|
|
60
|
+
return done();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
51
64
|
before(function (done) {
|
|
52
65
|
|
|
53
66
|
org2 = new Organization();
|
|
@@ -209,6 +222,45 @@ describe('Organization', function() {
|
|
|
209
222
|
|
|
210
223
|
});
|
|
211
224
|
|
|
225
|
+
before(function(done) {
|
|
226
|
+
|
|
227
|
+
var f = new Fund();
|
|
228
|
+
f.name = 'FUND XYZ';
|
|
229
|
+
f.shortName = 'xyz';
|
|
230
|
+
f.slug = 'fund-xyz';
|
|
231
|
+
|
|
232
|
+
Fund.upsert(f, 'test', function(err, fundResult) {
|
|
233
|
+
|
|
234
|
+
should.not.exist(err);
|
|
235
|
+
should.exist(fundResult);
|
|
236
|
+
|
|
237
|
+
someOtherFund = fundResult;
|
|
238
|
+
|
|
239
|
+
done();
|
|
240
|
+
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
before(function(done) {
|
|
246
|
+
|
|
247
|
+
var lp = new LimitedPartner();
|
|
248
|
+
lp.name = 'SOME OTHER LP';
|
|
249
|
+
lp.fundsInvested.push({fund:someOtherFund});
|
|
250
|
+
|
|
251
|
+
LimitedPartner.upsert(lp, 'test', 'lp-full', function(err, lpResult) {
|
|
252
|
+
|
|
253
|
+
should.not.exist(err);
|
|
254
|
+
should.exist(lpResult);
|
|
255
|
+
|
|
256
|
+
someOtherLp = lpResult;
|
|
257
|
+
|
|
258
|
+
done();
|
|
259
|
+
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
});
|
|
263
|
+
|
|
212
264
|
before(function(done) {
|
|
213
265
|
|
|
214
266
|
var providerEventId = 'some_other_random_data';
|
|
@@ -801,6 +853,46 @@ describe('Organization', function() {
|
|
|
801
853
|
|
|
802
854
|
});
|
|
803
855
|
|
|
856
|
+
it('gets lps', function(done) {
|
|
857
|
+
|
|
858
|
+
var lp = new LimitedPartner();
|
|
859
|
+
lp.name = 'LP';
|
|
860
|
+
lp.customer = config.CUSTOMER_ID;
|
|
861
|
+
|
|
862
|
+
LimitedPartner.upsert(lp, 'test', 'lp-full', function(err, lpResult) {
|
|
863
|
+
|
|
864
|
+
should.not.exist(err);
|
|
865
|
+
should.exist(lpResult);
|
|
866
|
+
|
|
867
|
+
var o = new Organization();
|
|
868
|
+
o.name = 'ORG';
|
|
869
|
+
o.slug = 'org';
|
|
870
|
+
o.website = 'org.org';
|
|
871
|
+
o.lps.push(lpResult);
|
|
872
|
+
o.lps.push(someOtherLp);
|
|
873
|
+
|
|
874
|
+
Organization.upsert(o, 'test-user', function(err, orgResult) {
|
|
875
|
+
|
|
876
|
+
should.not.exist(err);
|
|
877
|
+
should.exist(orgResult);
|
|
878
|
+
|
|
879
|
+
Organization.getById(orgResult._id, function(err, result) {
|
|
880
|
+
|
|
881
|
+
should.not.exist(err);
|
|
882
|
+
should.exist(result);
|
|
883
|
+
result.lps.length.should.equal(1);
|
|
884
|
+
result.lps[0]._id.toString().should.equal(lpResult._id.toString());
|
|
885
|
+
|
|
886
|
+
done();
|
|
887
|
+
|
|
888
|
+
});
|
|
889
|
+
|
|
890
|
+
});
|
|
891
|
+
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
});
|
|
895
|
+
|
|
804
896
|
it('cleans contact info', function(done) {
|
|
805
897
|
|
|
806
898
|
var o = new Organization();
|
|
@@ -905,6 +997,28 @@ describe('Organization', function() {
|
|
|
905
997
|
});
|
|
906
998
|
});
|
|
907
999
|
|
|
1000
|
+
it('cleans people', function(done) {
|
|
1001
|
+
|
|
1002
|
+
var littleDirtyOrg = new Organization();
|
|
1003
|
+
littleDirtyOrg.name = 'N00b';
|
|
1004
|
+
littleDirtyOrg.slug = 'n00b';
|
|
1005
|
+
|
|
1006
|
+
var temp = new mongoose.Types.ObjectId();
|
|
1007
|
+
|
|
1008
|
+
littleDirtyOrg.addPerson({person: temp});
|
|
1009
|
+
littleDirtyOrg.addPerson({person: temp});
|
|
1010
|
+
littleDirtyOrg.addPerson({person: new mongoose.Types.ObjectId()});
|
|
1011
|
+
littleDirtyOrg.addPerson({person: new mongoose.Types.ObjectId()});
|
|
1012
|
+
|
|
1013
|
+
Organization.upsert(littleDirtyOrg, 'test-user', function(err, result) {
|
|
1014
|
+
should.not.exist(err);
|
|
1015
|
+
should.exist(result);
|
|
1016
|
+
result.people.length.should.equal(3);
|
|
1017
|
+
return done();
|
|
1018
|
+
});
|
|
1019
|
+
|
|
1020
|
+
});
|
|
1021
|
+
|
|
908
1022
|
describe('State', function() {
|
|
909
1023
|
|
|
910
1024
|
it('gets ipo info', function(done) {
|