@dhyasama/totem-models 8.27.1 → 8.28.1

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 +67 -32
  2. package/package.json +1 -1
package/lib/Financials.js CHANGED
@@ -78,12 +78,10 @@ module.exports = function(mongoose, config) {
78
78
  amount: { type: Number, default: 0 },
79
79
  breakdown: { type: Schema.Types.Mixed }
80
80
  },
81
-
82
81
  liabilities: {
83
82
  amount: { type: Number, default: 0 },
84
83
  breakdown: { type: Schema.Types.Mixed }
85
84
  },
86
-
87
85
  equity: {
88
86
  amount: { type: Number, default: 0 },
89
87
  breakdown: { type: Schema.Types.Mixed }
@@ -94,12 +92,10 @@ module.exports = function(mongoose, config) {
94
92
  amount: { type: Number, default: 0 },
95
93
  breakdown: { type: Schema.Types.Mixed }
96
94
  },
97
-
98
95
  investingActivities: {
99
96
  amount: { type: Number, default: 0 },
100
97
  breakdown: { type: Schema.Types.Mixed }
101
98
  },
102
-
103
99
  financingActivities: {
104
100
  amount: { type: Number, default: 0 },
105
101
  breakdown: { type: Schema.Types.Mixed }
@@ -273,6 +269,8 @@ module.exports = function(mongoose, config) {
273
269
  { 'snapshots.notifications.company.initial.postmarkMessageId': postmarkMessageId },
274
270
  { 'snapshots.notifications.company.reminders.postmarkMessageId': postmarkMessageId },
275
271
  { 'snapshots.notifications.company.rejections.postmarkMessageId': postmarkMessageId },
272
+ { 'snapshots.notifications.stakeholders.initial.postmarkMessageId': postmarkMessageId },
273
+ { 'snapshots.notifications.stakeholders.reminders.postmarkMessageId': postmarkMessageId }
276
274
  ]
277
275
  });
278
276
 
@@ -280,7 +278,7 @@ module.exports = function(mongoose, config) {
280
278
 
281
279
  };
282
280
 
283
- Financials.statics.getInitialUUIDsToSend = function getInitialUUIDsToSend(cb) {
281
+ Financials.statics.getCompanyInitialUUIDsToSend = function getCompanyInitialUUIDsToSend(cb) {
284
282
 
285
283
  var self = this;
286
284
  var now = new Date();
@@ -318,7 +316,7 @@ module.exports = function(mongoose, config) {
318
316
 
319
317
  };
320
318
 
321
- Financials.statics.getReminderUUIDsToSend = function getReminderUUIDsToSend(cb) {
319
+ Financials.statics.getCompanyReminderUUIDsToSend = function getCompanyReminderUUIDsToSend(cb) {
322
320
 
323
321
  var self = this;
324
322
  var now = new Date();
@@ -369,7 +367,7 @@ module.exports = function(mongoose, config) {
369
367
 
370
368
  };
371
369
 
372
- Financials.statics.getRejectionUUIDsToSend = function getRejectionUUIDsToSend(cb) {
370
+ Financials.statics.getCompanyRejectionUUIDsToSend = function getCompanyRejectionUUIDsToSend(cb) {
373
371
 
374
372
  var self = this;
375
373
  var now = new Date();
@@ -413,63 +411,100 @@ module.exports = function(mongoose, config) {
413
411
 
414
412
  };
415
413
 
416
- Financials.statics.getForCustomer = function getForCustomer(customerId, cb) {
414
+ Financials.statics.getStakeholderInitialUUIDsToSend = function getStakeholderInitialUUIDsToSend(cb) {
417
415
 
418
416
  var self = this;
417
+ var now = new Date();
419
418
 
420
419
  var query = self.find({
421
- 'customer': customerId
420
+ 'snapshots': {
421
+ $elemMatch: {
422
+ 'notifications.stakeholders.sendTo': { $gt: [] },
423
+ 'notifications.stakeholders.organization': { $ne: null },
424
+ 'notifications.stakeholders.initial.sendOn': { $lte: now },
425
+ 'notifications.stakeholders.initial.sentOn': null
426
+ }
427
+ }
422
428
  });
423
429
 
424
- query.exec(cb);
430
+ query.exec(function(err, result) {
431
+
432
+ if (err) { return cb(err, null); }
433
+
434
+ var snapshots = _.pluck(result || [], 'snapshots');
435
+
436
+ snapshots = _.flatten(snapshots);
437
+
438
+ snapshots = _.filter(snapshots, function(snapshot) {
439
+
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;
443
+
444
+ return hasRecipients && hasOrganization && hasUnsentSendOnLessThanNow;
445
+
446
+ });
447
+
448
+ return cb(null, _.pluck(snapshots, 'uuid'));
449
+
450
+ });
425
451
 
426
452
  };
427
453
 
428
- Financials.statics.getManagedServicesForReview = function getManagedServicesForReview(customerId, cb) {
454
+ Financials.statics.getStakeholderReminderUUIDsToSend = function getStakeholderReminderUUIDsToSend(cb) {
429
455
 
430
456
  var self = this;
457
+ var now = new Date();
431
458
 
432
459
  var query = self.find({
433
- 'customer': customerId,
434
460
  'snapshots': {
435
461
  $elemMatch: {
436
- 'managedServices': true,
437
- 'submittedOn': { $ne: null },
438
- 'reviewedOn': null
462
+ 'notifications.stakeholders.sendTo': { $gt: [] },
463
+ 'notifications.stakeholders.organization': { $ne: null },
464
+ 'notifications.stakeholders.reminders.sendOn': { $lte: now },
465
+ 'notifications.stakeholders.reminders.sentOn': null
439
466
  }
440
467
  }
441
468
  });
442
469
 
443
- query.populate('organization', 'name');
444
-
445
- query.exec(function(err, results) {
470
+ query.exec(function(err, result) {
446
471
 
447
- var snapshots = [];
472
+ if (err) { return cb(err, null); }
448
473
 
449
- _.each(results, function(result) {
450
- _.each(result.snapshots, function(snapshot) {
474
+ var snapshots = _.pluck(result || [], 'snapshots');
451
475
 
452
- var isManagedServices = snapshot.managedServices;
453
- var isSubmitted = snapshot.submittedOn;
454
- var isNotReviewed = !snapshot.reviewedOn;
476
+ snapshots = _.flatten(snapshots);
455
477
 
456
- if(isManagedServices && isSubmitted && isNotReviewed) {
457
- snapshots.push({
458
- organization: result.organization.name,
459
- snapshot: snapshot
460
- });
461
- }
478
+ snapshots = _.filter(snapshots, function(snapshot) {
462
479
 
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;
463
484
  });
485
+
486
+ return hasRecipients && hasOrganization && hasUnsentSendOnLessThanNow;
487
+
464
488
  });
465
489
 
466
- if (err) { return cb(err, null); }
467
- return cb(null, snapshots);
490
+ return cb(null, _.pluck(snapshots, 'uuid'));
468
491
 
469
492
  });
470
493
 
471
494
  };
472
495
 
496
+ Financials.statics.getForCustomer = function getForCustomer(customerId, cb) {
497
+
498
+ var self = this;
499
+
500
+ var query = self.find({
501
+ 'customer': customerId
502
+ });
503
+
504
+ query.exec(cb);
505
+
506
+ };
507
+
473
508
  Financials.statics.getToSend = function getToSend(uuid, cb) {
474
509
 
475
510
  var self = this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "8.27.1",
3
+ "version": "8.28.1",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",