@dhyasama/totem-models 9.45.0 → 9.45.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 +26 -4
  2. package/package.json +1 -1
package/lib/Financials.js CHANGED
@@ -800,8 +800,12 @@ module.exports = function(mongoose, config) {
800
800
 
801
801
  Financials.statics.upsert = function upsert(financials, cb) {
802
802
 
803
+ console.log('Upsert financials');
804
+
803
805
  if (!financials) { return cb(new Error('financials is required'), null); }
804
806
 
807
+ console.log('Upsert financials id: ' + financials._id.toString());
808
+
805
809
  // Required for mixed types
806
810
  financials.markModified('metrics');
807
811
  financials.markModified('questions');
@@ -816,6 +820,8 @@ module.exports = function(mongoose, config) {
816
820
  financials.markModified('investingActivities.breakdown');
817
821
  financials.markModified('financingActivities.breakdown');
818
822
 
823
+ console.log('Upsert financials id: ' + financials._id.toString() + ' marked as modified');
824
+
819
825
  financials.save(cb);
820
826
 
821
827
  };
@@ -829,24 +835,34 @@ module.exports = function(mongoose, config) {
829
835
 
830
836
  const updateStatus = function updateStatus(self) {
831
837
 
838
+ console.log('Financials update status begin');
839
+
832
840
  _.each(self.snapshots, function(snapshot, index) {
833
841
 
834
- if(!snapshot) return;
842
+ console.log('Financials update status snapshot index ' + index.toString());
843
+
844
+ if (!snapshot) return;
845
+
846
+ console.log('Financials update status snapshot index ' + index.toString() + ' - 1');
835
847
 
836
848
  var needsReview = snapshot.review;
837
849
  var isSubmitted = snapshot.submittedOn;
838
850
  var isApproved = snapshot.approvedOn;
839
851
  var isRejected = snapshot.rejectedOn && snapshot.rejection;
840
852
  var isArchived = snapshot.archivedOn;
841
- var isOverdue = moment(new Date()).isAfter(moment(snapshot.dueOn));
842
-
853
+ var isOverdue = snapshot.dueOn ? moment(new Date()).isAfter(moment(snapshot.dueOn)) : false;
854
+
855
+ console.log('Financials update status snapshot index ' + index.toString() + ' - 2');
856
+
843
857
  var isOpened = false;
844
858
  var isDelivered = false;
845
859
  if(snapshot.notifications && snapshot.notifications.company && snapshot.notifications.company.initial) {
846
- isOpened = snapshot.notifications.company.initial.status && snapshot.notifications.company.initial.status == 'Opened' || snapshot.notifications.company.initial.status == 'Clicked';
860
+ isOpened = snapshot.notifications.company.initial.status && snapshot.notifications.company.initial.status === 'Opened' || snapshot.notifications.company.initial.status === 'Clicked';
847
861
  isDelivered = snapshot.notifications.company.initial.sentOn;
848
862
  }
849
863
 
864
+ console.log('Financials update status snapshot index ' + index.toString() + ' - 3');
865
+
850
866
  if(!snapshot.uuid) snapshot.status = 'Completed'; // no uuid means the snapshot was created from the google sheet and should always be completed
851
867
  else if(needsReview && isApproved) snapshot.status = 'Completed';
852
868
  else if(!needsReview && isSubmitted) snapshot.status = 'Completed';
@@ -858,8 +874,12 @@ module.exports = function(mongoose, config) {
858
874
  else if(isDelivered) snapshot.status = 'Delivered';
859
875
  else snapshot.status = 'Upcoming'; // Upcoming is set when a snapshot is created to be sent to an org, typically within a minute or so
860
876
 
877
+ console.log('Financials update status snapshot index ' + index.toString() + ' - 4');
878
+
861
879
  });
862
880
 
881
+ console.log('Financials update status end');
882
+
863
883
  };
864
884
 
865
885
  Financials.pre('init', function(next) {
@@ -867,6 +887,7 @@ module.exports = function(mongoose, config) {
867
887
  var self = this;
868
888
 
869
889
  updateStatus(self);
890
+
870
891
  return next();
871
892
 
872
893
  });
@@ -876,6 +897,7 @@ module.exports = function(mongoose, config) {
876
897
  const self = this;
877
898
 
878
899
  updateStatus(self);
900
+
879
901
  return next();
880
902
 
881
903
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "9.45.0",
3
+ "version": "9.45.2",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",