@dhyasama/totem-models 8.41.0 → 8.43.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/CapTable.js CHANGED
@@ -240,7 +240,7 @@ module.exports = function(mongoose, config) {
240
240
 
241
241
  CapTable.statics.deleteAllForCustomer = function(customerId, cb) {
242
242
  var self = this;
243
- self.remove({ customer: customerId }, cb);
243
+ self.remove({ customer: customerId, 'entered.by': { $ne: 'carta-parser' } }, cb);
244
244
  };
245
245
 
246
246
  CapTable.statics.getAllForCustomer = function getAllForCustomer(customerId, cb) {
@@ -354,7 +354,13 @@ module.exports = function(mongoose, config) {
354
354
 
355
355
  };
356
356
 
357
+ CapTable.statics.upsert = function upsert(capTable, cb) {
357
358
 
359
+ if (!capTable) { return cb(new Error('cap table is required'), null); }
360
+
361
+ capTable.save(cb);
362
+
363
+ }
358
364
 
359
365
  ///////////////////////////////////////////////////////////////////////////////////////
360
366
  // HOOKS
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "8.41.0",
3
+ "version": "8.43.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",