@dhyasama/totem-models 6.21.4 → 6.21.6
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/Organization.js +17 -2
- package/lib/Person.js +17 -2
- package/package.json +1 -1
- package/test/Organization.js +18 -0
- package/test/Person.js +18 -0
package/lib/Organization.js
CHANGED
|
@@ -1303,8 +1303,16 @@ module.exports = function(mongoose, config) {
|
|
|
1303
1303
|
|
|
1304
1304
|
var self = this;
|
|
1305
1305
|
|
|
1306
|
+
if (!value) { return cb(new Error('value must be provided'), null); }
|
|
1307
|
+
|
|
1306
1308
|
var getUsername = function getUsername(val) {
|
|
1307
1309
|
|
|
1310
|
+
if (!val) { return ''; }
|
|
1311
|
+
if (val.indexOf('@') === 0) { val = val.replace('@', ''); }
|
|
1312
|
+
|
|
1313
|
+
var username = '';
|
|
1314
|
+
var usernameRegExp = new RegExp("^[A-Za-z0-9_.@]{3,}$");
|
|
1315
|
+
var usernameMatch = [];
|
|
1308
1316
|
var URL = require('url');
|
|
1309
1317
|
var parsedUrl = URL.parse(val);
|
|
1310
1318
|
var protocol = parsedUrl.protocol;
|
|
@@ -1318,14 +1326,21 @@ module.exports = function(mongoose, config) {
|
|
|
1318
1326
|
if (pathname.indexOf('organization/') === 0) { pathname = pathname.replace('organization/', ''); }
|
|
1319
1327
|
if (pathname.indexOf('/') >= 0) { pathname = pathname.split('/')[0]; }
|
|
1320
1328
|
|
|
1321
|
-
|
|
1329
|
+
if (pathname) { usernameMatch = usernameRegExp.exec(pathname); }
|
|
1330
|
+
else { usernameMatch = usernameRegExp.exec(val); }
|
|
1331
|
+
|
|
1332
|
+
if (usernameMatch.length) { username = usernameMatch[0]; }
|
|
1322
1333
|
|
|
1323
|
-
|
|
1334
|
+
console.log('Username:', val, '-->', username);
|
|
1335
|
+
|
|
1336
|
+
return username;
|
|
1324
1337
|
|
|
1325
1338
|
};
|
|
1326
1339
|
|
|
1327
1340
|
var username = getUsername(value);
|
|
1328
1341
|
|
|
1342
|
+
if (!username) { return cb(null, []); }
|
|
1343
|
+
|
|
1329
1344
|
self
|
|
1330
1345
|
.find({ $or:
|
|
1331
1346
|
[
|
package/lib/Person.js
CHANGED
|
@@ -712,8 +712,16 @@ module.exports = function(mongoose, config) {
|
|
|
712
712
|
|
|
713
713
|
var self = this;
|
|
714
714
|
|
|
715
|
+
if (!value) { return cb(new Error('value must be provided'), null); }
|
|
716
|
+
|
|
715
717
|
var getUsername = function getUsername(val) {
|
|
716
718
|
|
|
719
|
+
if (!val) { return ''; }
|
|
720
|
+
if (val.indexOf('@') === 0) { val = val.replace('@', ''); }
|
|
721
|
+
|
|
722
|
+
var username = '';
|
|
723
|
+
var usernameRegExp = new RegExp("^[A-Za-z0-9_.@]{3,}$");
|
|
724
|
+
var usernameMatch = [];
|
|
717
725
|
var URL = require('url');
|
|
718
726
|
var parsedUrl = URL.parse(val);
|
|
719
727
|
var protocol = parsedUrl.protocol;
|
|
@@ -726,14 +734,21 @@ module.exports = function(mongoose, config) {
|
|
|
726
734
|
if (pathname.indexOf('in/') === 0) { pathname = pathname.replace('in/', ''); }
|
|
727
735
|
if (pathname.indexOf('/') >= 0) { pathname = pathname.split('/')[0]; }
|
|
728
736
|
|
|
729
|
-
|
|
737
|
+
if (pathname) { usernameMatch = usernameRegExp.exec(pathname); }
|
|
738
|
+
else { usernameMatch = usernameRegExp.exec(val); }
|
|
739
|
+
|
|
740
|
+
if (usernameMatch.length) { username = usernameMatch[0]; }
|
|
730
741
|
|
|
731
|
-
|
|
742
|
+
console.log('Username:', val, '-->', username);
|
|
743
|
+
|
|
744
|
+
return username;
|
|
732
745
|
|
|
733
746
|
};
|
|
734
747
|
|
|
735
748
|
var username = getUsername(value);
|
|
736
749
|
|
|
750
|
+
if (!username) { return cb(null, []); }
|
|
751
|
+
|
|
737
752
|
self
|
|
738
753
|
.find({ $or:
|
|
739
754
|
[
|
package/package.json
CHANGED
package/test/Organization.js
CHANGED
|
@@ -955,6 +955,24 @@ describe('Organization', function() {
|
|
|
955
955
|
});
|
|
956
956
|
});
|
|
957
957
|
|
|
958
|
+
it('finds orgs by social when just a username', function (done) {
|
|
959
|
+
Organization.findBySocial('abc', function (err, result) {
|
|
960
|
+
should.not.exist(err);
|
|
961
|
+
should.exist(result);
|
|
962
|
+
result.length.should.equal(1);
|
|
963
|
+
return done();
|
|
964
|
+
});
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
it('finds orgs by social when just a username with an at', function (done) {
|
|
968
|
+
Organization.findBySocial('@abc', function (err, result) {
|
|
969
|
+
should.not.exist(err);
|
|
970
|
+
should.exist(result);
|
|
971
|
+
result.length.should.equal(1);
|
|
972
|
+
return done();
|
|
973
|
+
});
|
|
974
|
+
});
|
|
975
|
+
|
|
958
976
|
it('finds orgs by ids', function (done) {
|
|
959
977
|
Organization.findByIds([org4._id, org5._id], function (err, result) {
|
|
960
978
|
should.not.exist(err);
|
package/test/Person.js
CHANGED
|
@@ -735,7 +735,25 @@ describe('Person', function() {
|
|
|
735
735
|
});
|
|
736
736
|
});
|
|
737
737
|
|
|
738
|
+
it('finds person by linkedin with just a handle', function (done) {
|
|
739
|
+
Person.findBySocial('slipperypete', function (err, result) {
|
|
740
|
+
should.not.exist(err);
|
|
741
|
+
should.exist(result);
|
|
742
|
+
result.length.should.equal(1);
|
|
743
|
+
result[0].slug.should.equal('person3-slug');
|
|
744
|
+
return done();
|
|
745
|
+
});
|
|
746
|
+
});
|
|
738
747
|
|
|
748
|
+
it('finds person by linkedin with just an at handle', function (done) {
|
|
749
|
+
Person.findBySocial('@slipperypete', function (err, result) {
|
|
750
|
+
should.not.exist(err);
|
|
751
|
+
should.exist(result);
|
|
752
|
+
result.length.should.equal(1);
|
|
753
|
+
result[0].slug.should.equal('person3-slug');
|
|
754
|
+
return done();
|
|
755
|
+
});
|
|
756
|
+
});
|
|
739
757
|
|
|
740
758
|
|
|
741
759
|
|