@dhyasama/totem-models 6.17.2 → 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/.npmignore +14 -0
- package/lib/Organization.js +53 -0
- package/lib/Person.js +53 -0
- package/package-lock.json +1829 -0
- package/package.json +1 -1
- package/test/Organization.js +6 -6
package/.npmignore
ADDED
package/lib/Organization.js
CHANGED
|
@@ -1297,6 +1297,59 @@ module.exports = function(mongoose, config) {
|
|
|
1297
1297
|
this.find({ 'slug': { $in : slugs } }).exec(cb);
|
|
1298
1298
|
};
|
|
1299
1299
|
|
|
1300
|
+
Organization.statics.findBySocial = function findBySocial(value, cb) {
|
|
1301
|
+
|
|
1302
|
+
// Extract stand-alone username and append it to our standardized domains
|
|
1303
|
+
|
|
1304
|
+
var self = this;
|
|
1305
|
+
|
|
1306
|
+
var getUsername = function getUsername(val) {
|
|
1307
|
+
|
|
1308
|
+
var URL = require('url');
|
|
1309
|
+
var result = URL.parse(val);
|
|
1310
|
+
|
|
1311
|
+
result = result.pathname;
|
|
1312
|
+
|
|
1313
|
+
if (result.indexOf('/') === 0) { result = result.replace('/', ''); }
|
|
1314
|
+
if (result.indexOf('in/') === 0) { result = result.replace('in/', ''); }
|
|
1315
|
+
if (result.indexOf('/') >= 0) { result = result.split('/')[0]; }
|
|
1316
|
+
|
|
1317
|
+
console.log(val, '-->', result);
|
|
1318
|
+
|
|
1319
|
+
};
|
|
1320
|
+
|
|
1321
|
+
var domains = {
|
|
1322
|
+
facebook: 'https://facebook.com',
|
|
1323
|
+
linkedin: 'https://linkedin.com',
|
|
1324
|
+
twitter: 'https://twitter.com'
|
|
1325
|
+
};
|
|
1326
|
+
|
|
1327
|
+
var username = getUsername(value);
|
|
1328
|
+
|
|
1329
|
+
// todo - tests
|
|
1330
|
+
// getUsername('dhyasama');
|
|
1331
|
+
// getUsername('in/dhyasama');
|
|
1332
|
+
// getUsername('http://facebook.com/dhyasama');
|
|
1333
|
+
// getUsername('http://linkedin.com/in/dhyasama');
|
|
1334
|
+
// getUsername('https://twitter.com/dhyasama');
|
|
1335
|
+
// getUsername('http://www.facebook.com/dhyasama');
|
|
1336
|
+
// getUsername('http://www.linkedin.com/dhyasama/');
|
|
1337
|
+
// getUsername('http://www.twitter.com/dhyasama?hello=world');
|
|
1338
|
+
// getUsername('http://www.facebook.com');
|
|
1339
|
+
|
|
1340
|
+
self
|
|
1341
|
+
.find({ $or:
|
|
1342
|
+
[
|
|
1343
|
+
{ 'social.facebook': domains.facebook + '/' + username },
|
|
1344
|
+
{ 'social.linkedin': domains.linkedin + '/in/' + username },
|
|
1345
|
+
{ 'social.twitter': domains.twitter + '/' + username }
|
|
1346
|
+
],
|
|
1347
|
+
'deleted': { $ne: true }
|
|
1348
|
+
})
|
|
1349
|
+
.exec(cb);
|
|
1350
|
+
|
|
1351
|
+
};
|
|
1352
|
+
|
|
1300
1353
|
Organization.statics.findDupes = function findDupes(org, options, cb) {
|
|
1301
1354
|
|
|
1302
1355
|
if (!cb) throw new Error('cb is required');
|
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
|
};
|