@dhyasama/totem-models 10.13.0 → 10.14.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/LimitedPartner.js +81 -4
- package/lib/Organization.js +283 -82
- package/lib/Person.js +74 -52
- package/package.json +1 -1
package/lib/LimitedPartner.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const _ = require("underscore");
|
|
4
|
+
const helpers = require("@dhyasama/totem-models/helpers");
|
|
3
5
|
module.exports = function(mongoose, config) {
|
|
4
6
|
|
|
5
7
|
let
|
|
@@ -185,14 +187,14 @@ module.exports = function(mongoose, config) {
|
|
|
185
187
|
});
|
|
186
188
|
|
|
187
189
|
LimitedPartner.virtual('fundsInvested').get(function () {
|
|
188
|
-
|
|
190
|
+
|
|
189
191
|
var self = this;
|
|
190
192
|
var fundsInvested = [];
|
|
191
|
-
|
|
193
|
+
|
|
192
194
|
_.each(self.transactions, function(transaction) {
|
|
193
|
-
|
|
195
|
+
|
|
194
196
|
var fundMatch = _.find(fundsInvested, function(fund) { return fund._id === transaction.fund._id; });
|
|
195
|
-
|
|
197
|
+
|
|
196
198
|
if(!fundMatch) {
|
|
197
199
|
fundsInvested.push({
|
|
198
200
|
_id: transaction.fund._id,
|
|
@@ -804,6 +806,81 @@ module.exports = function(mongoose, config) {
|
|
|
804
806
|
|
|
805
807
|
};
|
|
806
808
|
|
|
809
|
+
LimitedPartner.statics.search2 = function search2(value, options, cb) {
|
|
810
|
+
|
|
811
|
+
const self = this;
|
|
812
|
+
|
|
813
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
814
|
+
if (!value) { return cb(new Error('value is required'), null); }
|
|
815
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
816
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
817
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
818
|
+
|
|
819
|
+
const defaultOptions = {
|
|
820
|
+
limit: 10,
|
|
821
|
+
maxEdits: 1,
|
|
822
|
+
maxExpansions: 100
|
|
823
|
+
};
|
|
824
|
+
|
|
825
|
+
// combine provided and default options
|
|
826
|
+
options = _.defaults(options || {}, defaultOptions);
|
|
827
|
+
|
|
828
|
+
self.aggregate([
|
|
829
|
+
{
|
|
830
|
+
"$search": {
|
|
831
|
+
index: 'default',
|
|
832
|
+
compound: {
|
|
833
|
+
should: [
|
|
834
|
+
{
|
|
835
|
+
text: {
|
|
836
|
+
query: value,
|
|
837
|
+
path: [
|
|
838
|
+
'name',
|
|
839
|
+
'stakeholders'
|
|
840
|
+
],
|
|
841
|
+
fuzzy: {
|
|
842
|
+
maxEdits: options.maxEdits,
|
|
843
|
+
maxExpansions: options.maxExpansions
|
|
844
|
+
},
|
|
845
|
+
score: { boost: { value: 3 } }
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
],
|
|
849
|
+
must: [
|
|
850
|
+
{
|
|
851
|
+
equals: {
|
|
852
|
+
path: 'customer',
|
|
853
|
+
value: mongoose.Types.ObjectId(options.CUSTOMER_ID)
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
],
|
|
857
|
+
minimumShouldMatch: 1
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
},
|
|
861
|
+
{
|
|
862
|
+
$limit: options.limit,
|
|
863
|
+
},
|
|
864
|
+
{
|
|
865
|
+
$project: {
|
|
866
|
+
name: 1,
|
|
867
|
+
score: { $meta: "searchScore" }
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
]).exec(function(err, orgs) {
|
|
871
|
+
|
|
872
|
+
if (err) { return cb(err, null); }
|
|
873
|
+
|
|
874
|
+
orgs = _.map(orgs, function(org) {
|
|
875
|
+
return helpers.cleanOrg(org, options.CUSTOMER_ID);
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
return cb(null, orgs);
|
|
879
|
+
|
|
880
|
+
});
|
|
881
|
+
|
|
882
|
+
};
|
|
883
|
+
|
|
807
884
|
LimitedPartner.statics.upsert = function(lp, username, options, cb) {
|
|
808
885
|
|
|
809
886
|
if (!cb) { throw new Error('cb is required'); }
|
package/lib/Organization.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const _ = require("underscore");
|
|
4
|
+
const utilities = require("@dhyasama/totem-utilities");
|
|
5
|
+
const helpers = require("../helpers");
|
|
4
6
|
module.exports = function(mongoose, config) {
|
|
5
7
|
|
|
6
8
|
let
|
|
@@ -271,7 +273,7 @@ module.exports = function(mongoose, config) {
|
|
|
271
273
|
condition: { type: String, enum: [null, 'equals', 'doesNotEqual', 'contains', 'doesNotContain', 'lessThan', 'greaterThan', 'isEmpty', 'isNotEmpty'] },
|
|
272
274
|
values: [{ type: String, trim: true }]
|
|
273
275
|
}],
|
|
274
|
-
sort: {
|
|
276
|
+
sort: {
|
|
275
277
|
by: { type: String, trim: true },
|
|
276
278
|
reverse: { type: Boolean, default: false }
|
|
277
279
|
},
|
|
@@ -504,7 +506,7 @@ module.exports = function(mongoose, config) {
|
|
|
504
506
|
condition: { type: String, enum: [null, 'equals', 'doesNotEqual', 'contains', 'doesNotContain', 'lessThan', 'greaterThan', 'isEmpty', 'isNotEmpty'] },
|
|
505
507
|
values: [{ type: String, trim: true }]
|
|
506
508
|
}],
|
|
507
|
-
sort: {
|
|
509
|
+
sort: {
|
|
508
510
|
by: { type: String, trim: true },
|
|
509
511
|
reverse: { type: Boolean, default: false }
|
|
510
512
|
},
|
|
@@ -569,7 +571,7 @@ module.exports = function(mongoose, config) {
|
|
|
569
571
|
condition: { type: String, enum: [null, 'equals', 'doesNotEqual', 'contains', 'doesNotContain', 'lessThan', 'greaterThan', 'isEmpty', 'isNotEmpty'] },
|
|
570
572
|
values: [{ type: String, trim: true }]
|
|
571
573
|
}],
|
|
572
|
-
sort: {
|
|
574
|
+
sort: {
|
|
573
575
|
by: { type: String, trim: true },
|
|
574
576
|
reverse: { type: Boolean, default: false }
|
|
575
577
|
},
|
|
@@ -689,10 +691,8 @@ module.exports = function(mongoose, config) {
|
|
|
689
691
|
|
|
690
692
|
var self = this;
|
|
691
693
|
|
|
692
|
-
if (!self.customer) return [];
|
|
693
|
-
|
|
694
694
|
// Backwards schema compatibility
|
|
695
|
-
|
|
695
|
+
if (!self.customer.deals) return [];
|
|
696
696
|
|
|
697
697
|
// Deals aren't on for customer
|
|
698
698
|
else if (!self.customer.deals.active) return [];
|
|
@@ -817,8 +817,8 @@ module.exports = function(mongoose, config) {
|
|
|
817
817
|
Organization.virtual('operating.closed.on').get(function () {
|
|
818
818
|
|
|
819
819
|
const self = this;
|
|
820
|
-
const publicData = self.operating
|
|
821
|
-
const privateData = self.operating
|
|
820
|
+
const publicData = self.operating.closed.public || {};
|
|
821
|
+
const privateData = self.operating.closed.private || [];
|
|
822
822
|
|
|
823
823
|
if (publicData.closedOn) return publicData.closedOn;
|
|
824
824
|
else if (privateData.length >= 1) {
|
|
@@ -832,8 +832,8 @@ module.exports = function(mongoose, config) {
|
|
|
832
832
|
Organization.virtual('operating.closed.hasZeroUnrealizedValue').get(function () {
|
|
833
833
|
|
|
834
834
|
const self = this;
|
|
835
|
-
const publicData = self.operating
|
|
836
|
-
const privateData = self.operating
|
|
835
|
+
const publicData = self.operating.closed.public || {};
|
|
836
|
+
const privateData = self.operating.closed.private || [];
|
|
837
837
|
|
|
838
838
|
if (publicData.closedOn) return false;
|
|
839
839
|
else if (privateData.length >= 1) {
|
|
@@ -847,8 +847,8 @@ module.exports = function(mongoose, config) {
|
|
|
847
847
|
Organization.virtual('operating.acquired.amount').get(function () {
|
|
848
848
|
|
|
849
849
|
const self = this;
|
|
850
|
-
const publicData = self.operating
|
|
851
|
-
const privateData = self.operating
|
|
850
|
+
const publicData = self.operating.acquired.public || {};
|
|
851
|
+
const privateData = self.operating.acquired.private || [];
|
|
852
852
|
|
|
853
853
|
if (publicData.amount) return publicData.amount;
|
|
854
854
|
else if (privateData.length >= 1) {
|
|
@@ -862,8 +862,8 @@ module.exports = function(mongoose, config) {
|
|
|
862
862
|
Organization.virtual('operating.acquired.by').get(function () {
|
|
863
863
|
|
|
864
864
|
const self = this;
|
|
865
|
-
const publicData = self.operating
|
|
866
|
-
const privateData = self.operating
|
|
865
|
+
const publicData = self.operating.acquired.public || {};
|
|
866
|
+
const privateData = self.operating.acquired.private || [];
|
|
867
867
|
|
|
868
868
|
if (publicData.by) return publicData.by;
|
|
869
869
|
else if (privateData.length >= 1) {
|
|
@@ -877,8 +877,8 @@ module.exports = function(mongoose, config) {
|
|
|
877
877
|
Organization.virtual('operating.acquired.on').get(function () {
|
|
878
878
|
|
|
879
879
|
const self = this;
|
|
880
|
-
const publicData = self.operating
|
|
881
|
-
const privateData = self.operating
|
|
880
|
+
const publicData = self.operating.acquired.public || {};
|
|
881
|
+
const privateData = self.operating.acquired.private || [];
|
|
882
882
|
|
|
883
883
|
if (publicData.acquiredOn) return publicData.acquiredOn;
|
|
884
884
|
else if (privateData.length >= 1) {
|
|
@@ -892,8 +892,8 @@ module.exports = function(mongoose, config) {
|
|
|
892
892
|
Organization.virtual('operating.merged.with').get(function () {
|
|
893
893
|
|
|
894
894
|
const self = this;
|
|
895
|
-
const publicData = self.operating
|
|
896
|
-
const privateData = self.operating
|
|
895
|
+
const publicData = self.operating.merged.public || {};
|
|
896
|
+
const privateData = self.operating.merged.private || [];
|
|
897
897
|
|
|
898
898
|
if (publicData.with) return publicData.with;
|
|
899
899
|
else if (privateData.length >= 1) {
|
|
@@ -907,8 +907,8 @@ module.exports = function(mongoose, config) {
|
|
|
907
907
|
Organization.virtual('operating.merged.on').get(function () {
|
|
908
908
|
|
|
909
909
|
const self = this;
|
|
910
|
-
const publicData = self.operating
|
|
911
|
-
const privateData = self.operating
|
|
910
|
+
const publicData = self.operating.merged.public || {};
|
|
911
|
+
const privateData = self.operating.merged.private || [];
|
|
912
912
|
|
|
913
913
|
if (publicData.mergedOn) return publicData.mergedOn;
|
|
914
914
|
else if (privateData.length >= 1) {
|
|
@@ -931,7 +931,7 @@ module.exports = function(mongoose, config) {
|
|
|
931
931
|
else return 'Active';
|
|
932
932
|
|
|
933
933
|
});
|
|
934
|
-
|
|
934
|
+
|
|
935
935
|
Organization.virtual('websites').get(function () {
|
|
936
936
|
|
|
937
937
|
var self = this;
|
|
@@ -1270,11 +1270,11 @@ module.exports = function(mongoose, config) {
|
|
|
1270
1270
|
|
|
1271
1271
|
self
|
|
1272
1272
|
.find({ $or:
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1273
|
+
[
|
|
1274
|
+
{ 'people.person': personId },
|
|
1275
|
+
{ 'chairs.first': personId },
|
|
1276
|
+
{ 'chairs.second': personId }
|
|
1277
|
+
],
|
|
1278
1278
|
'deleted': { $ne: true }
|
|
1279
1279
|
})
|
|
1280
1280
|
.select('-sources -customer')
|
|
@@ -1290,6 +1290,87 @@ module.exports = function(mongoose, config) {
|
|
|
1290
1290
|
this.find({ 'slug': { $in : slugs } }).exec(cb);
|
|
1291
1291
|
};
|
|
1292
1292
|
|
|
1293
|
+
Organization.statics.findBySocial2 = function findBySocial2(value, options, cb) {
|
|
1294
|
+
|
|
1295
|
+
// Extract stand-alone username and append it to our standardized domains
|
|
1296
|
+
|
|
1297
|
+
const self = this;
|
|
1298
|
+
|
|
1299
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
1300
|
+
if (!value) { return cb(new Error('value is required'), null); }
|
|
1301
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
1302
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
1303
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
1304
|
+
|
|
1305
|
+
const defaultMaxEdits = 1;
|
|
1306
|
+
const defaultMaxExpansions = 100;
|
|
1307
|
+
const username = utilities.getUsernameFromUrl(value);
|
|
1308
|
+
|
|
1309
|
+
if (!username) { return cb(null, []); }
|
|
1310
|
+
|
|
1311
|
+
self.aggregate([
|
|
1312
|
+
{
|
|
1313
|
+
"$search": {
|
|
1314
|
+
index: 'organizations_search_autocomplete',
|
|
1315
|
+
compound: {
|
|
1316
|
+
should: [
|
|
1317
|
+
{
|
|
1318
|
+
autocomplete: {
|
|
1319
|
+
query: username,
|
|
1320
|
+
path: 'social_handle.facebook',
|
|
1321
|
+
fuzzy: {
|
|
1322
|
+
maxEdits: defaultMaxEdits,
|
|
1323
|
+
maxExpansions: defaultMaxExpansions
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
},
|
|
1327
|
+
{
|
|
1328
|
+
autocomplete: {
|
|
1329
|
+
query: username,
|
|
1330
|
+
path: 'social_handle.linkedin',
|
|
1331
|
+
fuzzy: {
|
|
1332
|
+
maxEdits: defaultMaxEdits,
|
|
1333
|
+
maxExpansions: defaultMaxExpansions
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
},
|
|
1337
|
+
{
|
|
1338
|
+
autocomplete: {
|
|
1339
|
+
query: username,
|
|
1340
|
+
path: 'social_handle.twitter',
|
|
1341
|
+
fuzzy: {
|
|
1342
|
+
maxEdits: defaultMaxEdits,
|
|
1343
|
+
maxExpansions: defaultMaxExpansions
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
],
|
|
1348
|
+
must: [
|
|
1349
|
+
{
|
|
1350
|
+
equals: {
|
|
1351
|
+
path: 'deleted',
|
|
1352
|
+
value: false
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
],
|
|
1356
|
+
minimumShouldMatch: 1
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
]).exec(function(err, orgs) {
|
|
1361
|
+
|
|
1362
|
+
if (err) { return cb(err, null); }
|
|
1363
|
+
|
|
1364
|
+
orgs = _.map(orgs, function(org) {
|
|
1365
|
+
return helpers.cleanOrg(org, options.CUSTOMER_ID);
|
|
1366
|
+
});
|
|
1367
|
+
|
|
1368
|
+
return cb(null, orgs);
|
|
1369
|
+
|
|
1370
|
+
});
|
|
1371
|
+
|
|
1372
|
+
};
|
|
1373
|
+
|
|
1293
1374
|
Organization.statics.findBySocial = function findBySocial(value, options, cb) {
|
|
1294
1375
|
|
|
1295
1376
|
// Extract stand-alone username and append it to our standardized domains
|
|
@@ -1349,24 +1430,24 @@ module.exports = function(mongoose, config) {
|
|
|
1349
1430
|
|
|
1350
1431
|
self
|
|
1351
1432
|
.find({ $or:
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1433
|
+
[
|
|
1434
|
+
{ 'social.facebook': {$in: facebookRegexes }},
|
|
1435
|
+
{ 'social.linkedin': {$in: linkedinRegexes }},
|
|
1436
|
+
{ 'social.twitter': {$in: twitterRegexes }},
|
|
1437
|
+
{ 'crunchbase.url': {$in: crunchbaseRegexes }}
|
|
1438
|
+
],
|
|
1358
1439
|
'deleted': { $ne: true }
|
|
1359
1440
|
}).exec(function(err, orgs) {
|
|
1360
1441
|
|
|
1361
|
-
|
|
1442
|
+
if (err) { return cb(err, null); }
|
|
1362
1443
|
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1444
|
+
orgs = _.map(orgs, function(org) {
|
|
1445
|
+
return helpers.cleanOrg(org, options.CUSTOMER_ID);
|
|
1446
|
+
});
|
|
1366
1447
|
|
|
1367
|
-
|
|
1448
|
+
return cb(null, orgs);
|
|
1368
1449
|
|
|
1369
|
-
|
|
1450
|
+
});
|
|
1370
1451
|
|
|
1371
1452
|
};
|
|
1372
1453
|
|
|
@@ -1388,9 +1469,9 @@ module.exports = function(mongoose, config) {
|
|
|
1388
1469
|
self
|
|
1389
1470
|
.find(
|
|
1390
1471
|
{ $or: [
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1472
|
+
{ 'operating.acquired.private.by': orgid, 'operating.acquired.private.customer': options.CUSTOMER_ID, 'deleted': { $ne: true } },
|
|
1473
|
+
{ 'operating.acquired.public.by': orgid, 'deleted': { $ne: true } },
|
|
1474
|
+
]}
|
|
1394
1475
|
)
|
|
1395
1476
|
.select('name logoUrl')
|
|
1396
1477
|
.exec(cb);
|
|
@@ -1504,10 +1585,10 @@ module.exports = function(mongoose, config) {
|
|
|
1504
1585
|
|
|
1505
1586
|
self
|
|
1506
1587
|
.find({ $or:
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1588
|
+
[
|
|
1589
|
+
{ 'chairs.first': personId },
|
|
1590
|
+
{ 'chairs.second': personId }
|
|
1591
|
+
],
|
|
1511
1592
|
'deleted': { $ne: true }
|
|
1512
1593
|
})
|
|
1513
1594
|
.exec(function(err, orgs) {
|
|
@@ -1593,16 +1674,16 @@ module.exports = function(mongoose, config) {
|
|
|
1593
1674
|
|
|
1594
1675
|
query.exec(function(err, orgs) {
|
|
1595
1676
|
|
|
1596
|
-
|
|
1597
|
-
|
|
1677
|
+
if (err) { return cb(err, null); }
|
|
1678
|
+
else if (!orgs) { return cb(null, []); }
|
|
1598
1679
|
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1680
|
+
orgs = _.map(orgs, function(org) {
|
|
1681
|
+
return helpers.cleanOrg(org, options.CUSTOMER_ID);
|
|
1682
|
+
});
|
|
1602
1683
|
|
|
1603
|
-
|
|
1684
|
+
return cb(null, orgs);
|
|
1604
1685
|
|
|
1605
|
-
|
|
1686
|
+
});
|
|
1606
1687
|
|
|
1607
1688
|
};
|
|
1608
1689
|
|
|
@@ -1674,50 +1755,50 @@ module.exports = function(mongoose, config) {
|
|
|
1674
1755
|
// get the org requested
|
|
1675
1756
|
query.exec(function(err, org) {
|
|
1676
1757
|
|
|
1677
|
-
|
|
1678
|
-
|
|
1758
|
+
if (err) { return cb(err, null); }
|
|
1759
|
+
if (!org) { return cb(null, null); }
|
|
1679
1760
|
|
|
1680
|
-
|
|
1681
|
-
|
|
1761
|
+
// get the customer requesting org
|
|
1762
|
+
self.findById(options.CUSTOMER_ID, function(err, customer) {
|
|
1682
1763
|
|
|
1683
|
-
|
|
1684
|
-
|
|
1764
|
+
if (err) { return cb(err, null); }
|
|
1765
|
+
if (!customer) { return cb(null, null); }
|
|
1685
1766
|
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1767
|
+
let current = [];
|
|
1768
|
+
let past = [];
|
|
1769
|
+
let all = [];
|
|
1689
1770
|
|
|
1690
|
-
|
|
1691
|
-
|
|
1771
|
+
// combined list of sources from each person at org
|
|
1772
|
+
let orgSources = helpers.getPeopleSources(_.pluck(org.people, 'person'));
|
|
1692
1773
|
|
|
1693
|
-
|
|
1694
|
-
|
|
1774
|
+
// loop through customer's people and categorize sources
|
|
1775
|
+
_.each(customer.people, function(p) {
|
|
1695
1776
|
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1777
|
+
var source = _.find(orgSources, function(os) {
|
|
1778
|
+
if (!os || !os.person || !os.person._id) return false;
|
|
1779
|
+
return os.person._id.toString() === p.person.toString();
|
|
1780
|
+
});
|
|
1700
1781
|
|
|
1701
|
-
|
|
1782
|
+
if (!source) return;
|
|
1702
1783
|
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1784
|
+
if (p.current) current.push(source);
|
|
1785
|
+
if (!p.current) past.push(source);
|
|
1786
|
+
all.push(source);
|
|
1706
1787
|
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
// todo - fix sorting
|
|
1710
|
-
// return categorized sources
|
|
1711
|
-
return cb(null, {
|
|
1712
|
-
all: all, //helpers.sortPeopleSources(all, options.CUSTOMER_ID),
|
|
1713
|
-
current: current, //helpers.sortPeopleSources(current, options.CUSTOMER_ID),
|
|
1714
|
-
past: past //helpers.sortPeopleSources(past, options.CUSTOMER_ID)
|
|
1715
|
-
});
|
|
1788
|
+
});
|
|
1716
1789
|
|
|
1790
|
+
// todo - fix sorting
|
|
1791
|
+
// return categorized sources
|
|
1792
|
+
return cb(null, {
|
|
1793
|
+
all: all, //helpers.sortPeopleSources(all, options.CUSTOMER_ID),
|
|
1794
|
+
current: current, //helpers.sortPeopleSources(current, options.CUSTOMER_ID),
|
|
1795
|
+
past: past //helpers.sortPeopleSources(past, options.CUSTOMER_ID)
|
|
1717
1796
|
});
|
|
1718
1797
|
|
|
1719
1798
|
});
|
|
1720
1799
|
|
|
1800
|
+
});
|
|
1801
|
+
|
|
1721
1802
|
};
|
|
1722
1803
|
|
|
1723
1804
|
Organization.statics.modify = function(filter, update, cb) {
|
|
@@ -1789,6 +1870,47 @@ module.exports = function(mongoose, config) {
|
|
|
1789
1870
|
|
|
1790
1871
|
};
|
|
1791
1872
|
|
|
1873
|
+
// Organization.statics.atlasSearch = function (query, options, cb) {
|
|
1874
|
+
//
|
|
1875
|
+
// const self = this;
|
|
1876
|
+
//
|
|
1877
|
+
// const defaultOptions = {
|
|
1878
|
+
// limit: 100
|
|
1879
|
+
// };
|
|
1880
|
+
//
|
|
1881
|
+
// // combine provided and default options
|
|
1882
|
+
// options = _.defaults(options || {}, defaultOptions);
|
|
1883
|
+
//
|
|
1884
|
+
// self.aggregate([
|
|
1885
|
+
// {
|
|
1886
|
+
// '$search': {
|
|
1887
|
+
// 'index': 'default',
|
|
1888
|
+
// 'text': {
|
|
1889
|
+
// 'query': query,
|
|
1890
|
+
// 'path': {
|
|
1891
|
+
// 'wildcard': '*'
|
|
1892
|
+
// }
|
|
1893
|
+
// }
|
|
1894
|
+
// }
|
|
1895
|
+
// }, {
|
|
1896
|
+
// '$match': {
|
|
1897
|
+
// 'deleted': false
|
|
1898
|
+
// }
|
|
1899
|
+
// }, {
|
|
1900
|
+
// $limit: options.limit,
|
|
1901
|
+
// }, {
|
|
1902
|
+
// "$project": {
|
|
1903
|
+
// "_id": 1,
|
|
1904
|
+
// "fullName": 1,
|
|
1905
|
+
// "name": 1,
|
|
1906
|
+
// "avatarUrl": 1,
|
|
1907
|
+
// "score": { "$meta": "searchScore" }
|
|
1908
|
+
// }
|
|
1909
|
+
// }
|
|
1910
|
+
// ], cb);
|
|
1911
|
+
//
|
|
1912
|
+
// };
|
|
1913
|
+
|
|
1792
1914
|
Organization.statics.search = function search(data, options, cb) {
|
|
1793
1915
|
|
|
1794
1916
|
// search for orgs based on fields provided
|
|
@@ -1946,6 +2068,85 @@ module.exports = function(mongoose, config) {
|
|
|
1946
2068
|
|
|
1947
2069
|
};
|
|
1948
2070
|
|
|
2071
|
+
Organization.statics.search2 = function search2(value, options, cb) {
|
|
2072
|
+
|
|
2073
|
+
const self = this;
|
|
2074
|
+
|
|
2075
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
2076
|
+
if (!value) { return cb(new Error('value is required'), null); }
|
|
2077
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
2078
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
2079
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
2080
|
+
|
|
2081
|
+
const defaultOptions = {
|
|
2082
|
+
limit: 10,
|
|
2083
|
+
maxEdits: 1,
|
|
2084
|
+
maxExpansions: 100
|
|
2085
|
+
};
|
|
2086
|
+
|
|
2087
|
+
// combine provided and default options
|
|
2088
|
+
options = _.defaults(options || {}, defaultOptions);
|
|
2089
|
+
|
|
2090
|
+
self.aggregate([
|
|
2091
|
+
{
|
|
2092
|
+
"$search": {
|
|
2093
|
+
index: 'default',
|
|
2094
|
+
compound: {
|
|
2095
|
+
should: [
|
|
2096
|
+
{
|
|
2097
|
+
text: {
|
|
2098
|
+
query: value,
|
|
2099
|
+
path: [
|
|
2100
|
+
'name',
|
|
2101
|
+
'aliases',
|
|
2102
|
+
'website',
|
|
2103
|
+
'websiteAliases',
|
|
2104
|
+
'stakeholders'
|
|
2105
|
+
],
|
|
2106
|
+
fuzzy: {
|
|
2107
|
+
maxEdits: options.maxEdits,
|
|
2108
|
+
maxExpansions: options.maxExpansions
|
|
2109
|
+
},
|
|
2110
|
+
score: { boost: { value: 3 } }
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
],
|
|
2114
|
+
must: [
|
|
2115
|
+
{
|
|
2116
|
+
equals: {
|
|
2117
|
+
path: 'deleted',
|
|
2118
|
+
value: false
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
],
|
|
2122
|
+
minimumShouldMatch: 1
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
},
|
|
2126
|
+
{
|
|
2127
|
+
$limit: options.limit,
|
|
2128
|
+
},
|
|
2129
|
+
{
|
|
2130
|
+
$project: {
|
|
2131
|
+
name: 1,
|
|
2132
|
+
logoUrl: 1,
|
|
2133
|
+
score: { $meta: "searchScore" }
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
]).exec(function(err, orgs) {
|
|
2137
|
+
|
|
2138
|
+
if (err) { return cb(err, null); }
|
|
2139
|
+
|
|
2140
|
+
orgs = _.map(orgs, function(org) {
|
|
2141
|
+
return helpers.cleanOrg(org, options.CUSTOMER_ID);
|
|
2142
|
+
});
|
|
2143
|
+
|
|
2144
|
+
return cb(null, orgs);
|
|
2145
|
+
|
|
2146
|
+
});
|
|
2147
|
+
|
|
2148
|
+
};
|
|
2149
|
+
|
|
1949
2150
|
Organization.statics.upsert = function(org, username, cb) {
|
|
1950
2151
|
|
|
1951
2152
|
if (!org) { return cb(new Error('Organization is required'), null); }
|
package/lib/Person.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
const _ = require("underscore");
|
|
4
|
-
|
|
4
|
+
module.exports = function(mongoose, config) {
|
|
5
5
|
|
|
6
6
|
let
|
|
7
7
|
|
|
@@ -145,7 +145,7 @@ const _ = require("underscore");
|
|
|
145
145
|
Person.virtual('name.full').get(function () {
|
|
146
146
|
var name = '';
|
|
147
147
|
if(this.name.first) name += this.name.first;
|
|
148
|
-
if(this.name.first && this.name.last) name += ' ';
|
|
148
|
+
if(this.name.first && this.name.last) name += ' ';
|
|
149
149
|
if(this.name.last) name += this.name.last;
|
|
150
150
|
return name;
|
|
151
151
|
});
|
|
@@ -178,7 +178,7 @@ const _ = require("underscore");
|
|
|
178
178
|
|
|
179
179
|
Person.methods.addMerged = function(id) {
|
|
180
180
|
if (this.merged.indexOf(id) == -1) {
|
|
181
|
-
|
|
181
|
+
this.merged = this.merged.concat([id]);
|
|
182
182
|
return true;
|
|
183
183
|
}
|
|
184
184
|
else {
|
|
@@ -395,12 +395,12 @@ const _ = require("underscore");
|
|
|
395
395
|
|
|
396
396
|
self
|
|
397
397
|
.find({ $or:
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
398
|
+
[
|
|
399
|
+
{ 'social.facebook': {$in: facebookRegexes }},
|
|
400
|
+
{ 'social.linkedin': {$in: linkedinRegexes }},
|
|
401
|
+
{ 'social.twitter': {$in: twitterRegexes }},
|
|
402
|
+
{ 'crunchbase.url': {$in: crunchbaseRegexes }}
|
|
403
|
+
],
|
|
404
404
|
'deleted': { $ne: true }
|
|
405
405
|
}).exec(cb);
|
|
406
406
|
|
|
@@ -664,47 +664,6 @@ const _ = require("underscore");
|
|
|
664
664
|
|
|
665
665
|
};
|
|
666
666
|
|
|
667
|
-
Person.statics.atlasSearch = function (query, options, cb) {
|
|
668
|
-
|
|
669
|
-
const self = this;
|
|
670
|
-
|
|
671
|
-
const defaultOptions = {
|
|
672
|
-
limit: 100
|
|
673
|
-
};
|
|
674
|
-
|
|
675
|
-
// combine provided and default options
|
|
676
|
-
options = _.defaults(options || {}, defaultOptions);
|
|
677
|
-
|
|
678
|
-
self.aggregate([
|
|
679
|
-
{
|
|
680
|
-
'$search': {
|
|
681
|
-
'index': 'default',
|
|
682
|
-
'text': {
|
|
683
|
-
'query': query,
|
|
684
|
-
'path': {
|
|
685
|
-
'wildcard': '*'
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
}, {
|
|
690
|
-
'$match': {
|
|
691
|
-
'deleted': false
|
|
692
|
-
}
|
|
693
|
-
}, {
|
|
694
|
-
$limit: options.limit,
|
|
695
|
-
}, {
|
|
696
|
-
"$project": {
|
|
697
|
-
"_id": 1,
|
|
698
|
-
"fullName": 1,
|
|
699
|
-
"name": 1,
|
|
700
|
-
"avatarUrl": 1,
|
|
701
|
-
"score": { "$meta": "searchScore" }
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
], cb);
|
|
705
|
-
|
|
706
|
-
};
|
|
707
|
-
|
|
708
667
|
// search for people based on fields provided
|
|
709
668
|
// Data format, everything is optional
|
|
710
669
|
//{
|
|
@@ -742,7 +701,7 @@ const _ = require("underscore");
|
|
|
742
701
|
delete query['$and'];
|
|
743
702
|
}
|
|
744
703
|
|
|
745
|
-
|
|
704
|
+
// "and" is only used for name, which is one more thing to "or" so move it to "or"
|
|
746
705
|
// note that changes may be needed if "and" is used for other things as well
|
|
747
706
|
else {
|
|
748
707
|
query['$or'].push({ '$and': query['$and'] });
|
|
@@ -1041,6 +1000,69 @@ const _ = require("underscore");
|
|
|
1041
1000
|
|
|
1042
1001
|
};
|
|
1043
1002
|
|
|
1003
|
+
Person.statics.search2 = function (query, options, cb) {
|
|
1004
|
+
|
|
1005
|
+
const self = this;
|
|
1006
|
+
|
|
1007
|
+
const defaultOptions = {
|
|
1008
|
+
limit: 10,
|
|
1009
|
+
maxEdits: 1,
|
|
1010
|
+
maxExpansions: 100
|
|
1011
|
+
};
|
|
1012
|
+
|
|
1013
|
+
// combine provided and default options
|
|
1014
|
+
options = _.defaults(options || {}, defaultOptions);
|
|
1015
|
+
|
|
1016
|
+
self.aggregate([
|
|
1017
|
+
{
|
|
1018
|
+
"$search": {
|
|
1019
|
+
index: 'default',
|
|
1020
|
+
compound: {
|
|
1021
|
+
should: [
|
|
1022
|
+
{
|
|
1023
|
+
text: {
|
|
1024
|
+
query: query,
|
|
1025
|
+
path: [
|
|
1026
|
+
'name.first',
|
|
1027
|
+
'name.last',
|
|
1028
|
+
'fullName',
|
|
1029
|
+
'aliases',
|
|
1030
|
+
'stakeholders'
|
|
1031
|
+
],
|
|
1032
|
+
fuzzy: {
|
|
1033
|
+
maxEdits: options.maxEdits,
|
|
1034
|
+
maxExpansions: options.maxExpansions
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
],
|
|
1039
|
+
must: [
|
|
1040
|
+
{
|
|
1041
|
+
equals: {
|
|
1042
|
+
path: 'deleted',
|
|
1043
|
+
value: false
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
],
|
|
1047
|
+
minimumShouldMatch: 1
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
}, {
|
|
1051
|
+
$limit: options.limit,
|
|
1052
|
+
}, {
|
|
1053
|
+
"$project": {
|
|
1054
|
+
"_id": 1,
|
|
1055
|
+
"fullName": 1,
|
|
1056
|
+
"name": 1,
|
|
1057
|
+
"avatarUrl": 1,
|
|
1058
|
+
"sources": 1,
|
|
1059
|
+
"score": { "$meta": "searchScore" }
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
], cb);
|
|
1063
|
+
|
|
1064
|
+
};
|
|
1065
|
+
|
|
1044
1066
|
Person.statics.searchByEmail = function(email, cb) {
|
|
1045
1067
|
|
|
1046
1068
|
if (!cb) throw new Error('cb is required');
|