@dhyasama/totem-models 9.43.0 → 9.43.2

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.
Files changed (2) hide show
  1. package/lib/Financials.js +18 -22
  2. package/package.json +1 -1
package/lib/Financials.js CHANGED
@@ -601,43 +601,41 @@ module.exports = function(mongoose, config) {
601
601
  }
602
602
  });
603
603
 
604
- query.exec(function(err, result) {
604
+ query.exec(function(err, financials) {
605
605
 
606
606
  if (err) { return cb(err, null); }
607
607
 
608
+ financials = financials || [];
609
+
608
610
  let results = [];
609
611
 
610
- _.each(result, function(financial) {
612
+ _.each(financials, function(financial) {
611
613
 
612
- let result = {
613
- 'financials': financial,
614
- 'snapshotUUID': null,
615
- 'stakeholderIdsToNotify': [],
616
- 'uuid': null, // todo - legacy, to be removed
617
- 'recipients': null, // todo - legacy, to be removed
618
- 'stakeholder': null // todo - legacy, to be removed
619
- };
614
+ if (!financial) return;
620
615
 
621
616
  _.each(financial.snapshots, function(snapshot) {
622
617
 
623
- result.snapshotUUID = snapshot.uuid;
624
- result.uuid = snapshot.uuid; // legacy, tbr
618
+ if (!snapshot || !snapshot.uuid || !snapshot.notifications || !snapshot.notifications.stakeholders) return;
625
619
 
626
620
  _.each(snapshot.notifications.stakeholders, function(stakeholder) {
627
621
 
628
- const hasSendToEmail = stakeholder.sendTo && stakeholder.sendTo.email;
629
- const sendOnLessThanNow = stakeholder.initial && stakeholder.initial.sendOn < now;
622
+ if (!stakeholder || !stakeholder._id || !stakeholder.sendTo || !stakeholder.initial) return;
623
+
624
+ const sendToEmail = stakeholder.sendTo.email;
625
+ const sendOnLessThanNow = stakeholder.initial.sendOn < now;
630
626
  const sentOn = stakeholder.initial.sentOn;
631
627
  const sentToQueue = stakeholder.initial.sentToQueue;
632
- const conditionsMet = hasSendToEmail && sendOnLessThanNow && !sentOn && !sentToQueue;
628
+ const conditionsMet = sendToEmail && sendOnLessThanNow && !sentOn && !sentToQueue;
633
629
 
634
630
  if (conditionsMet) {
635
631
 
636
- result.stakeholderIdsToNotify.push(stakeholder._id);
637
-
638
- // todo - legacy, to be removed
639
- result.recipients = [stakeholder.sendTo.email];
640
- result.stakeholder = stakeholder;
632
+ results.push({
633
+ 'financials': financial,
634
+ 'snapshotUUID': snapshot.uuid,
635
+ 'stakeholderId': stakeholder._id,
636
+ 'uuid': snapshot.uuid, // todo - legacy, to be removed
637
+ 'recipients': [stakeholder.sendTo.email] // todo - legacy, to be removed
638
+ });
641
639
 
642
640
  }
643
641
 
@@ -645,8 +643,6 @@ module.exports = function(mongoose, config) {
645
643
 
646
644
  });
647
645
 
648
- if (result.stakeholderIdsToNotify.length) { results.push(result); }
649
-
650
646
  });
651
647
 
652
648
  return cb(null, results);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "9.43.0",
3
+ "version": "9.43.2",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",