@dhyasama/totem-models 6.17.2 → 6.17.3

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 ADDED
@@ -0,0 +1,14 @@
1
+ lib-cov
2
+ *.seed
3
+ *.log
4
+ *.csv
5
+ *.dat
6
+ *.out
7
+ *.pid
8
+ *.gz
9
+
10
+ npm-debug.log
11
+ node_modules
12
+
13
+ .DS_Store
14
+ .idea
@@ -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');