@dhyasama/totem-models 6.21.5 → 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.
@@ -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,9 +1326,14 @@ 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
- console.log('Username:', val, '-->', pathname);
1329
+ if (pathname) { usernameMatch = usernameRegExp.exec(pathname); }
1330
+ else { usernameMatch = usernameRegExp.exec(val); }
1331
+
1332
+ if (usernameMatch.length) { username = usernameMatch[0]; }
1333
+
1334
+ console.log('Username:', val, '-->', username);
1322
1335
 
1323
- return pathname;
1336
+ return username;
1324
1337
 
1325
1338
  };
1326
1339
 
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,9 +734,14 @@ 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
- console.log('Username:', val, '-->', pathname);
737
+ if (pathname) { usernameMatch = usernameRegExp.exec(pathname); }
738
+ else { usernameMatch = usernameRegExp.exec(val); }
739
+
740
+ if (usernameMatch.length) { username = usernameMatch[0]; }
741
+
742
+ console.log('Username:', val, '-->', username);
730
743
 
731
- return pathname;
744
+ return username;
732
745
 
733
746
  };
734
747
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "6.21.5",
3
+ "version": "6.21.6",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
@@ -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