@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.
- package/lib/Financials.js +18 -22
- 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,
|
|
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(
|
|
612
|
+
_.each(financials, function(financial) {
|
|
611
613
|
|
|
612
|
-
|
|
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
|
-
|
|
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
|
-
|
|
629
|
-
|
|
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 =
|
|
628
|
+
const conditionsMet = sendToEmail && sendOnLessThanNow && !sentOn && !sentToQueue;
|
|
633
629
|
|
|
634
630
|
if (conditionsMet) {
|
|
635
631
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
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);
|