@dhyasama/totem-models 11.90.0 → 11.93.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.
- package/lib/Deal.js +38 -9
- package/lib/Financials.js +1 -1
- package/package.json +1 -1
package/lib/Deal.js
CHANGED
|
@@ -758,25 +758,54 @@ module.exports = function(mongoose, config) {
|
|
|
758
758
|
if (!deal) { return cb(new Error('deal is required'), null); }
|
|
759
759
|
if (!options) { return cb(new Error('options is required'), null); }
|
|
760
760
|
|
|
761
|
-
let
|
|
761
|
+
let getPreviousStage = function(currentStage) {
|
|
762
762
|
|
|
763
763
|
if (!deal.history || deal.history.length === 0) return null;
|
|
764
764
|
|
|
765
|
-
let
|
|
766
|
-
let last = history[history.length - 1];
|
|
765
|
+
let previous = null;
|
|
767
766
|
|
|
768
|
-
|
|
767
|
+
for (let i = 0; i < deal.history.length; i++) {
|
|
768
|
+
const item = deal.history[i];
|
|
769
|
+
if (!item || !item.stage) continue;
|
|
770
|
+
if (item.stage === currentStage) continue;
|
|
771
|
+
|
|
772
|
+
if (!previous || new Date(item.timestamp).getTime() > new Date(previous.timestamp).getTime()) {
|
|
773
|
+
previous = item;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
return previous ? previous.stage : null;
|
|
769
778
|
|
|
770
779
|
};
|
|
771
780
|
|
|
781
|
+
// Determine if any meaningful fields have actually changed
|
|
782
|
+
const trackedPaths = ['action', 'source', 'referrer', 'fundraise', 'resources', 'documents', 'customFields'];
|
|
783
|
+
let otherChanged = false;
|
|
784
|
+
if (deal._originalTracked) {
|
|
785
|
+
const afterNormalized = normalizeTrackedFromDoc(deal);
|
|
786
|
+
otherChanged = trackedPaths.some(function(path) {
|
|
787
|
+
return !_.isEqual(deal._originalTracked[path], afterNormalized[path]);
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
else {
|
|
791
|
+
otherChanged = deal.isModified ? trackedPaths.some(function(path) { return deal.isModified(path); }) : false;
|
|
792
|
+
}
|
|
793
|
+
|
|
772
794
|
let description = '';
|
|
773
|
-
|
|
795
|
+
const stageChanged = (typeof deal.isModified === 'function') ? deal.isModified('stage') : false;
|
|
796
|
+
const previousStage = stageChanged ? getPreviousStage(deal.stage) : null;
|
|
774
797
|
|
|
775
|
-
if (
|
|
776
|
-
|
|
777
|
-
|
|
798
|
+
if (deal.isNew) {
|
|
799
|
+
description = 'The deal was created';
|
|
800
|
+
}
|
|
801
|
+
else if (stageChanged) {
|
|
802
|
+
description = 'The deal was updated from ' + previousStage + ' to ' + deal.stage;
|
|
803
|
+
}
|
|
804
|
+
else if (otherChanged) {
|
|
805
|
+
description = 'The deal details were updated';
|
|
806
|
+
}
|
|
778
807
|
|
|
779
|
-
//
|
|
808
|
+
// Only add history and bump lastUpdated if there were actual changes
|
|
780
809
|
if (description !== '') {
|
|
781
810
|
|
|
782
811
|
deal.history = deal.history || [];
|
package/lib/Financials.js
CHANGED
|
@@ -84,7 +84,7 @@ module.exports = function(mongoose, config) {
|
|
|
84
84
|
status: { type: String, enum: ['Created', 'Scheduled', 'Delivered', 'Opened', 'Overdue', 'In Review', 'Completed', 'Archived'] },
|
|
85
85
|
|
|
86
86
|
year: { type: Number, default: 0 },
|
|
87
|
-
period: { type: String, enum: ['Annual', 'Q1', 'Q2', 'Q3', 'Q4', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] },
|
|
87
|
+
period: { type: String, enum: ['Annual', 'H1', 'H2', 'Q1', 'Q2', 'Q3', 'Q4', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] },
|
|
88
88
|
|
|
89
89
|
form: [{
|
|
90
90
|
name: { type: String, trim: true },
|