@dhyasama/totem-models 8.28.1 → 8.29.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.
Files changed (2) hide show
  1. package/lib/Financials.js +25 -19
  2. package/package.json +1 -1
package/lib/Financials.js CHANGED
@@ -30,7 +30,6 @@ module.exports = function(mongoose, config) {
30
30
  managedServices: { type: Boolean, default: false, required: true },
31
31
 
32
32
  status: { type: String },
33
-
34
33
  action: { type: String },
35
34
 
36
35
  year: { type: Number, default: 0 },
@@ -147,12 +146,11 @@ module.exports = function(mongoose, config) {
147
146
 
148
147
  stakeholders: [{
149
148
 
150
- organization: { type: Schema.ObjectId, ref: 'Organization' },
151
-
152
- sendTo: [{
149
+ sendTo: {
150
+ organization: { type: Schema.ObjectId, ref: 'Organization' },
153
151
  email: { type: String, trim: true },
154
152
  name: { type: String, trim: true }
155
- }],
153
+ },
156
154
 
157
155
  initial: {
158
156
  sendOn: { type: Date, required: false },
@@ -419,8 +417,8 @@ module.exports = function(mongoose, config) {
419
417
  var query = self.find({
420
418
  'snapshots': {
421
419
  $elemMatch: {
422
- 'notifications.stakeholders.sendTo': { $gt: [] },
423
- 'notifications.stakeholders.organization': { $ne: null },
420
+ 'notifications.stakeholders.sendTo.email': { $ne: null },
421
+ 'notifications.stakeholders.sendTo.organization': { $ne: null },
424
422
  'notifications.stakeholders.initial.sendOn': { $lte: now },
425
423
  'notifications.stakeholders.initial.sentOn': null
426
424
  }
@@ -437,11 +435,15 @@ module.exports = function(mongoose, config) {
437
435
 
438
436
  snapshots = _.filter(snapshots, function(snapshot) {
439
437
 
440
- var hasRecipients = snapshot.notifications.stakeholders.sendTo.length > 0;
441
- var hasOrganization = snapshot.notifications.stakeholders.organization;
442
- var hasUnsentSendOnLessThanNow = snapshot.notifications.stakeholders.initial.sendOn < now && !snapshot.notifications.stakeholders.initial.sentOn;
438
+ return _.some(snapshot.notifications.stakeholders, function(stakeholder) {
439
+
440
+ var hasEmail = stakeholder.sendTo && stakeholder.sendTo.email;
441
+ var hasOrganization = stakeholder.sendTo && stakeholder.sendTo.organization;
442
+ var hasUnsentSendOnLessThanNow = stakeholder.initial && stakeholder.initial.sendOn < now && !stakeholder.initial.sentOn;
443
443
 
444
- return hasRecipients && hasOrganization && hasUnsentSendOnLessThanNow;
444
+ return hasEmail && hasOrganization && hasUnsentSendOnLessThanNow;
445
+
446
+ });
445
447
 
446
448
  });
447
449
 
@@ -459,8 +461,8 @@ module.exports = function(mongoose, config) {
459
461
  var query = self.find({
460
462
  'snapshots': {
461
463
  $elemMatch: {
462
- 'notifications.stakeholders.sendTo': { $gt: [] },
463
- 'notifications.stakeholders.organization': { $ne: null },
464
+ 'notifications.stakeholders.sendTo.email': { $ne: null },
465
+ 'notifications.stakeholders.sendTo.organization': { $ne: null },
464
466
  'notifications.stakeholders.reminders.sendOn': { $lte: now },
465
467
  'notifications.stakeholders.reminders.sentOn': null
466
468
  }
@@ -477,13 +479,17 @@ module.exports = function(mongoose, config) {
477
479
 
478
480
  snapshots = _.filter(snapshots, function(snapshot) {
479
481
 
480
- var hasRecipients = snapshot.notifications.stakeholders.sendTo.length > 0;
481
- var hasOrganization = snapshot.notifications.stakeholders.organization;
482
- var hasUnsentSendOnLessThanNow = _.find(snapshot.notifications.stakeholders.reminders, function(reminder) {
483
- return reminder.sendOn < now && !reminder.sentOn;
484
- });
482
+ return _.some(snapshot.notifications.stakeholders, function(stakeholder) {
485
483
 
486
- return hasRecipients && hasOrganization && hasUnsentSendOnLessThanNow;
484
+ var hasEmail = stakeholder.sendTo && stakeholder.sendTo.email;
485
+ var hasOrganization = stakeholder.sendTo && stakeholder.sendTo.organization;
486
+ var hasUnsentSendOnLessThanNow = _.find(stakeholder.reminders, function(reminder) {
487
+ return reminder.sendOn < now && !reminder.sentOn;
488
+ });
489
+
490
+ return hasEmail && hasOrganization && hasUnsentSendOnLessThanNow;
491
+
492
+ });
487
493
 
488
494
  });
489
495
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "8.28.1",
3
+ "version": "8.29.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",