@dhyasama/totem-models 5.3.1 → 5.3.3

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/.npmignore ADDED
@@ -0,0 +1,14 @@
1
+ lib-cov
2
+ *.seed
3
+ *.log
4
+ *.csv
5
+ *.dat
6
+ *.out
7
+ *.pid
8
+ *.gz
9
+
10
+ npm-debug.log
11
+ node_modules
12
+
13
+ .DS_Store
14
+ .idea
package/lib/Deal.js CHANGED
@@ -19,12 +19,12 @@ module.exports = function(mongoose, config) {
19
19
 
20
20
  sources: [{
21
21
  person: { type: Schema.ObjectId, ref: 'Person', required: true },
22
- type: { type: String, enum: ['inbound', 'outbound', 'event', 'referral', 'other'], required: true }
22
+ type: { type: String, enum: ['Inbound', 'Outbound', 'Event', 'Referral', 'Other'], required: true }
23
23
  }],
24
24
 
25
25
  referrers: [{
26
26
  person: { type: Schema.ObjectId, ref: 'Person', required: true },
27
- type: { type: String, enum: ['founder', 'investor', 'service-provider', 'friends-and-family', 'limited-partner', 'other'], required: true }
27
+ type: { type: String, enum: ['Founder', 'Investor', 'Service Provider', 'Friends & Family', 'Limited Partner', 'Other'], required: true }
28
28
  }],
29
29
 
30
30
  documents: [ { type: Schema.ObjectId, ref: 'Document' } ],
@@ -118,16 +118,21 @@ module.exports = function(mongoose, config) {
118
118
  };
119
119
 
120
120
  // Get all deals belonging to a customer
121
- Deal.statics.getForCustomer = function (customerId, activeCustomerStages, cb) {
122
-
123
- var self = this;
121
+ Deal.statics.getForCustomer = function (customerId, options, cb) {
124
122
 
125
123
  // todo - fix deep population
126
124
  // not sure why chained deepPopulate isn't working (it throws an error)
127
125
  // it works to deepPopulate each result instance in parallel
128
126
 
127
+ var self = this;
128
+
129
+ options = options || {};
130
+
131
+ var terms = { 'customer': customerId };
132
+ if (options.stage) terms['stage'] = { $in: options.stage };
133
+
129
134
  self
130
- .find({ 'customer': customerId, 'stage': { $in: activeCustomerStages } })
135
+ .find(terms)
131
136
  .populate('organization', 'name description logoUrl website websiteAliases chairs')
132
137
  .populate('messages')
133
138
  .populate('sources.person', 'name avatarUrl title')
@@ -145,6 +150,9 @@ module.exports = function(mongoose, config) {
145
150
  // })
146
151
  .exec(function(err, deals) {
147
152
 
153
+ if (err) return cb(err, null);
154
+ else if (!deals || deals.length == 0) return cb(null, []);
155
+
148
156
  var calls = [];
149
157
 
150
158
  _.each(deals, function(deal) {
@@ -1084,6 +1084,9 @@ module.exports = function(mongoose, config) {
1084
1084
  var lpPopulateOptions = { path: 'lps' };
1085
1085
  if (config.CUSTOMER_ID != 'GLOBAL_PROCESS') lpPopulateOptions.match = { customer: config.CUSTOMER_ID };
1086
1086
 
1087
+ var dealPopulateOptions = { path: 'deals' };
1088
+ if (config.CUSTOMER_ID != 'GLOBAL_PROCESS') dealPopulateOptions.match = { customer: config.CUSTOMER_ID };
1089
+
1087
1090
  var query = self.findById(id);
1088
1091
 
1089
1092
  query.populate('people.person', 'name avatarUrl title contact doNotDisplay');
@@ -1093,11 +1096,7 @@ module.exports = function(mongoose, config) {
1093
1096
  query.populate('funds', 'name hexColorCode abbreviation closeDate');
1094
1097
  query.populate('operating.acquired.public.by', 'name logoUrl');
1095
1098
  query.populate('operating.acquired.private.by', 'name logoUrl');
1096
-
1097
- query.populate({
1098
- path: 'deals',
1099
- match: { customer: config.CUSTOMER_ID }
1100
- });
1099
+ query.populate(dealPopulateOptions);
1101
1100
 
1102
1101
  if (options.role != 'none') {
1103
1102
  query.populate(lpPopulateOptions);