@dhyasama/totem-models 9.123.0 → 9.126.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/Deal.js CHANGED
@@ -61,8 +61,9 @@ module.exports = function(mongoose, config) {
61
61
  latestMessage: { type: Schema.ObjectId, ref: 'Message', required: false },
62
62
 
63
63
  applications: [{
64
- name: { type: String, trim: true },
65
- appliedOn: { type: Date, default: Date.now }
64
+ application: { type: String, trim: true },
65
+ appliedOn: { type: Date, default: Date.now },
66
+ appliedBy: { type: String, trim: true }
66
67
  }]
67
68
 
68
69
  });
@@ -249,6 +250,27 @@ module.exports = function(mongoose, config) {
249
250
 
250
251
  };
251
252
 
253
+ Deal.statics.getByApplication = function (application, options, cb) {
254
+
255
+ let self = this;
256
+
257
+ if (!cb) { throw new Error('cb is required'); }
258
+ if (!personId) { return cb(new Error('personId is required'), null); }
259
+ if (!mongoose.Types.ObjectId.isValid(personId)) { return cb(new Error('personId is not a valid ObjectId'), null); }
260
+ if (!options) { return cb(new Error('options is required'), null); }
261
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
262
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
263
+
264
+ let query = self.find({
265
+ 'applications.application': application,
266
+ 'customer': options.CUSTOMER_ID
267
+ });
268
+
269
+ query.populate('organization', 'name description');
270
+ query.exec(cb);
271
+
272
+ };
273
+
252
274
  // Get a deal for a org, belonging to current customer
253
275
  Deal.statics.getForOrg = function (orgId, options, cb) {
254
276
 
@@ -1317,6 +1317,46 @@ module.exports = function(mongoose, config) {
1317
1317
 
1318
1318
  };
1319
1319
 
1320
+ Organization.statics.findBySocials = function findBySocials(values, options, cb) {
1321
+
1322
+ // Extract usernames and append it to our standardized domains
1323
+
1324
+ const self = this;
1325
+
1326
+ if (!cb) { throw new Error('cb is required'); }
1327
+ if (!values) { return cb(new Error('values is required'), null); }
1328
+ if (!options) { return cb(new Error('options is required'), null); }
1329
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
1330
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
1331
+
1332
+ let facebookRegexes = _.map(values, function(value) { new RegExp('facebook.com/' + utilities.getUsernameFromUrl(value) + '\/?$', 'i') });
1333
+ let linkedinRegexes = _.map(values, function(value) { new RegExp('linkedin.com/company/' + utilities.getUsernameFromUrl(value) + '\/?$', 'i') });
1334
+ let twitterRegexes = _.map(values, function(value) { new RegExp('twitter.com/' + utilities.getUsernameFromUrl(value) + '\/?$', 'i') });
1335
+ let crunchbaseRegexes = _.map(values, function(value) { new RegExp('crunchbase.com/organization/' + utilities.getUsernameFromUrl(value) + '\/?$', 'i') });
1336
+
1337
+ self
1338
+ .find({ $or:
1339
+ [
1340
+ { 'social.facebook': {$in: facebookRegexes }},
1341
+ { 'social.linkedin': {$in: linkedinRegexes }},
1342
+ { 'social.twitter': {$in: twitterRegexes }},
1343
+ { 'crunchbase.url': {$in: crunchbaseRegexes }}
1344
+ ],
1345
+ 'deleted': { $ne: true }
1346
+ }).exec(function(err, orgs) {
1347
+
1348
+ if (err) { return cb(err, null); }
1349
+
1350
+ orgs = _.map(orgs, function(org) {
1351
+ return helpers.cleanOrg(org, options.CUSTOMER_ID);
1352
+ });
1353
+
1354
+ return cb(null, orgs);
1355
+
1356
+ });
1357
+
1358
+ };
1359
+
1320
1360
  Organization.statics.findByTotemUrl = function findByTotemUrl(url, cb) {
1321
1361
  this.findOne({ 'customer.totemUrl': url }).exec(cb);
1322
1362
  };
package/lib/Person.js CHANGED
@@ -68,7 +68,8 @@ module.exports = function(mongoose, config) {
68
68
  },
69
69
 
70
70
  crunchbase: {
71
- uuid: { type: String, unique: true, required: false, partialFilterExpression : { type :"string" }, trim: true }
71
+ uuid: { type: String, unique: true, required: false, partialFilterExpression : { type :"string" }, trim: true },
72
+ url: { type: String, unique: true, partialFilterExpression : { type :"string" }, trim: true }
72
73
  },
73
74
 
74
75
  vCardUrl: { type: String, default: null, trim: true },
@@ -377,6 +378,33 @@ module.exports = function(mongoose, config) {
377
378
 
378
379
  };
379
380
 
381
+ Person.statics.findBySocials = function findBySocials(values, cb) {
382
+
383
+ // Extract usernames and append it to our standardized domains
384
+
385
+ const self = this;
386
+
387
+ if (!cb) { throw new Error('cb is required'); }
388
+ if (!values) { return cb(new Error('values is required'), null); }
389
+
390
+ let facebookRegexes = _.map(values, function(value) { new RegExp('facebook.com/' + utilities.getUsernameFromUrl(value) + '\/?$', 'i') });
391
+ let linkedinRegexes = _.map(values, function(value) { new RegExp('linkedin.com/company/' + utilities.getUsernameFromUrl(value) + '\/?$', 'i') });
392
+ let twitterRegexes = _.map(values, function(value) { new RegExp('twitter.com/' + utilities.getUsernameFromUrl(value) + '\/?$', 'i') });
393
+ let crunchbaseRegexes = _.map(values, function(value) { new RegExp('crunchbase.com/organization/' + utilities.getUsernameFromUrl(value) + '\/?$', 'i') });
394
+
395
+ self
396
+ .find({ $or:
397
+ [
398
+ { 'social.facebook': {$in: facebookRegexes }},
399
+ { 'social.linkedin': {$in: linkedinRegexes }},
400
+ { 'social.twitter': {$in: twitterRegexes }},
401
+ { 'crunchbase.url': {$in: crunchbaseRegexes }}
402
+ ],
403
+ 'deleted': { $ne: true }
404
+ }).exec(cb);
405
+
406
+ };
407
+
380
408
  Person.statics.getById = function (id, options, cb) {
381
409
 
382
410
  const self = this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "9.123.0",
3
+ "version": "9.126.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",