@dhyasama/totem-models 6.17.3 → 6.18.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/Person.js CHANGED
@@ -706,6 +706,59 @@ 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
+ };
729
+
730
+ var domains = {
731
+ facebook: 'https://facebook.com',
732
+ linkedin: 'https://linkedin.com',
733
+ twitter: 'https://twitter.com'
734
+ };
735
+
736
+ var username = getUsername(value);
737
+
738
+ // todo - tests
739
+ // getUsername('dhyasama');
740
+ // getUsername('in/dhyasama');
741
+ // getUsername('http://facebook.com/dhyasama');
742
+ // getUsername('http://linkedin.com/in/dhyasama');
743
+ // getUsername('https://twitter.com/dhyasama');
744
+ // getUsername('http://www.facebook.com/dhyasama');
745
+ // getUsername('http://www.linkedin.com/dhyasama/');
746
+ // getUsername('http://www.twitter.com/dhyasama?hello=world');
747
+ // getUsername('http://www.facebook.com');
748
+
749
+ self
750
+ .find({ $or:
751
+ [
752
+ { 'social.facebook': domains.facebook + '/' + username },
753
+ { 'social.linkedin': domains.linkedin + '/in/' + username },
754
+ { 'social.twitter': domains.twitter + '/' + username }
755
+ ],
756
+ 'deleted': { $ne: true }
757
+ })
758
+ .exec(cb);
759
+
760
+ };
761
+
709
762
  Person.statics.stats = function (cb) {
710
763
  this.collection.stats(cb);
711
764
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "6.17.3",
3
+ "version": "6.18.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);