@dhyasama/totem-models 8.42.0 → 8.44.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/Financials.js CHANGED
@@ -11,7 +11,6 @@ module.exports = function(mongoose, config) {
11
11
 
12
12
  var Schema = mongoose.Schema;
13
13
  var Account = mongoose.model('Account');
14
- var async = require('async');
15
14
  var _ = require('underscore');
16
15
  var moment = require('moment');
17
16
 
@@ -477,46 +476,33 @@ module.exports = function(mongoose, config) {
477
476
 
478
477
  var results = [];
479
478
 
480
- async.each(result, function(financial, callback1) {
479
+ _.each(result, function(financial) {
481
480
 
482
- async.each(financial.snapshots, function(snapshot, callback2) {
481
+ _.each(financial.snapshots, function(snapshot) {
483
482
 
484
- async.each(snapshot.notifications.stakeholders, function(stakeholder, callback3) {
483
+ _.each(snapshot.notifications.stakeholders, function(stakeholder) {
485
484
 
486
485
  var hasEmail = stakeholder.sendTo && stakeholder.sendTo.email;
487
486
  var hasOrganization = stakeholder.sendTo && stakeholder.sendTo.organization;
488
487
  var hasUnsentSendOnLessThanNow = stakeholder.initial && stakeholder.initial.sendOn < now && !stakeholder.initial.sentOn;
489
488
 
490
- if (!hasEmail || !hasOrganization || !hasUnsentSendOnLessThanNow) return callback3();
491
-
492
- Account.findByEmail(stakeholder.sendTo.email, function(err, account) {
493
-
494
- var hasAccount = !_.isEmpty(account);
495
- var hasAccessToken = !_.isEmpty(account) && account.auth && (account.auth.google && account.auth.google.accessToken) || (account.auth.microsoft && account.auth.microsoft.accessToken);
496
-
497
- if (!hasAccount || hasAccessToken) return callback3();
489
+ if(hasEmail && hasOrganization && hasUnsentSendOnLessThanNow) {
498
490
 
499
491
  results.push({
500
492
  'uuid': snapshot.uuid,
501
493
  'recipients': [stakeholder.sendTo.email]
502
494
  });
503
495
 
504
- return callback3();
505
-
506
- });
496
+ }
507
497
 
508
- }, function (err) {
509
- return callback2(err, results);
510
498
  });
511
499
 
512
- }, function (err) {
513
- return callback1(err, results);
514
500
  });
515
501
 
516
- }, function (err) {
517
- return cb(err, results);
518
502
  });
519
503
 
504
+ return cb(null, results);
505
+
520
506
  });
521
507
 
522
508
  };
@@ -543,48 +529,39 @@ module.exports = function(mongoose, config) {
543
529
 
544
530
  var results = [];
545
531
 
546
- async.each(result, function(financial, callback1) {
532
+ _.each(result, function(financial) {
547
533
 
548
- async.each(financial.snapshots, function(snapshot, callback2) {
534
+ _.each(financial.snapshots, function(snapshot) {
549
535
 
550
- async.each(snapshot.notifications.stakeholders, function(stakeholder, callback3) {
536
+ _.each(snapshot.notifications.stakeholders, function(stakeholder) {
551
537
 
552
538
  var hasEmail = stakeholder.sendTo && stakeholder.sendTo.email;
553
539
  var hasOrganization = stakeholder.sendTo && stakeholder.sendTo.organization;
554
540
  var hasUnsentSendOnLessThanNow = _.find(stakeholder.reminders, function(reminder) {
555
541
  return reminder.sendOn < now && !reminder.sentOn;
556
542
  });
543
+ var hasNotClickedInitial = stakeholder.initial && stakeholder.initial.status != 'Clicked';
544
+ var hasNotClickedReminder = _.every(stakeholder.reminders, function(reminder) {
545
+ return reminder.status != 'Clicked';
546
+ });
557
547
 
558
- if (!hasEmail || !hasOrganization || !hasUnsentSendOnLessThanNow) return callback3();
559
-
560
- Account.findByEmail(stakeholder.sendTo.email, function(err, account) {
561
-
562
- var hasAccount = !_.isEmpty(account);
563
- var hasAccessToken = !_.isEmpty(account) && account.auth && (account.auth.google && account.auth.google.accessToken) || (account.auth.microsoft && account.auth.microsoft.accessToken);
548
+ if(hasEmail && hasOrganization && hasUnsentSendOnLessThanNow && hasNotClickedInitial && hasNotClickedReminder) {
564
549
 
565
- if (!hasAccount || hasAccessToken) return callback3();
566
-
567
550
  results.push({
568
551
  'uuid': snapshot.uuid,
569
552
  'recipients': [stakeholder.sendTo.email]
570
553
  });
571
554
 
572
- return callback3();
573
-
574
- });
555
+ }
575
556
 
576
- }, function (err) {
577
- return callback2(err, results);
578
557
  });
579
558
 
580
- }, function (err) {
581
- return callback1(err, results);
582
559
  });
583
560
 
584
- }, function (err) {
585
- return cb(err, results);
586
561
  });
587
562
 
563
+ return cb(null, results);
564
+
588
565
  });
589
566
 
590
567
  };
@@ -1696,6 +1696,20 @@ module.exports = function(mongoose, config) {
1696
1696
 
1697
1697
  };
1698
1698
 
1699
+ Organization.statics.removeCustomerValuations = function(customerId, cb) {
1700
+
1701
+ var self = this;
1702
+
1703
+ self
1704
+ .update(
1705
+ { 'valuations.customer': customerId },
1706
+ { $pull : { 'valuations': { 'customer': customerId } } },
1707
+ { multi : true }
1708
+ )
1709
+ .exec(cb);
1710
+
1711
+ };
1712
+
1699
1713
  Organization.statics.search = function search(data, options, cb) {
1700
1714
 
1701
1715
  // search for orgs based on fields provided
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "8.42.0",
3
+ "version": "8.44.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",