@dhyasama/totem-models 6.17.3 → 6.19.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.
@@ -1316,6 +1316,8 @@ module.exports = function(mongoose, config) {
1316
1316
 
1317
1317
  console.log(val, '-->', result);
1318
1318
 
1319
+ return result;
1320
+
1319
1321
  };
1320
1322
 
1321
1323
  var domains = {
package/lib/Person.js CHANGED
@@ -706,6 +706,61 @@ module.exports = function(mongoose, config) {
706
706
 
707
707
  };
708
708
 
709
+ Person.statics.findBySocial = function findBySocial(value, cb) {
710
+
711
+ // Extract stand-alone username and append it to our standardized domains
712
+
713
+ var self = this;
714
+
715
+ var getUsername = function getUsername(val) {
716
+
717
+ var URL = require('url');
718
+ var result = URL.parse(val);
719
+
720
+ result = result.pathname;
721
+
722
+ if (result.indexOf('/') === 0) { result = result.replace('/', ''); }
723
+ if (result.indexOf('in/') === 0) { result = result.replace('in/', ''); }
724
+ if (result.indexOf('/') >= 0) { result = result.split('/')[0]; }
725
+
726
+ console.log(val, '-->', result);
727
+
728
+ return result;
729
+
730
+ };
731
+
732
+ var domains = {
733
+ facebook: 'https://facebook.com',
734
+ linkedin: 'https://linkedin.com',
735
+ twitter: 'https://twitter.com'
736
+ };
737
+
738
+ var username = getUsername(value);
739
+
740
+ // todo - tests
741
+ // getUsername('dhyasama');
742
+ // getUsername('in/dhyasama');
743
+ // getUsername('http://facebook.com/dhyasama');
744
+ // getUsername('http://linkedin.com/in/dhyasama');
745
+ // getUsername('https://twitter.com/dhyasama');
746
+ // getUsername('http://www.facebook.com/dhyasama');
747
+ // getUsername('http://www.linkedin.com/dhyasama/');
748
+ // getUsername('http://www.twitter.com/dhyasama?hello=world');
749
+ // getUsername('http://www.facebook.com');
750
+
751
+ self
752
+ .find({ $or:
753
+ [
754
+ { 'social.facebook': domains.facebook + '/' + username },
755
+ { 'social.linkedin': domains.linkedin + '/in/' + username },
756
+ { 'social.twitter': domains.twitter + '/' + username }
757
+ ],
758
+ 'deleted': { $ne: true }
759
+ })
760
+ .exec(cb);
761
+
762
+ };
763
+
709
764
  Person.statics.stats = function (cb) {
710
765
  this.collection.stats(cb);
711
766
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "6.17.3",
3
+ "version": "6.19.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
@@ -70,7 +70,7 @@ describe('Organization', function() {
70
70
  org2.name = 'No Thanks 2';
71
71
  org2.slug = 'org2-slug';
72
72
  org2.website = 'nothanks2.org';
73
- org2.websiteAliases = ['myolddomain.tld'];
73
+ org2.websiteAliases = ['myolddomain.ch'];
74
74
  org2.related = [];
75
75
  org2.aliases.push('NT2');
76
76
  org2.crunchbase.uuid = 'abc';
@@ -899,7 +899,7 @@ describe('Organization', function() {
899
899
  });
900
900
 
901
901
  it('finds org by domain alias', function (done) {
902
- Organization.findByDomains(['doesnotexist.io', 'myolddomain.tld'], function (err, result) {
902
+ Organization.findByDomains(['doesnotexist.io', 'myolddomain.ch'], function (err, result) {
903
903
  should.not.exist(err);
904
904
  should.exist(result);
905
905
  result.length.should.equal(1);
@@ -1327,11 +1327,11 @@ describe('Organization', function() {
1327
1327
 
1328
1328
  config.CUSTOMER_ID = customer2._id.toString();
1329
1329
 
1330
- var org2 = new Organization();
1331
- org2.name = 'Newest Co';
1332
- org2.slug = 'newest-co';
1330
+ var org6 = new Organization();
1331
+ org6.name = 'Newest Co';
1332
+ org6.slug = 'newest-co';
1333
1333
 
1334
- Organization.upsert(org2, 'test-user', function(err, result1) {
1334
+ Organization.upsert(org6, 'test-user', function(err, result1) {
1335
1335
 
1336
1336
  should.not.exist(err);
1337
1337
  should.exist(result1);