@dhyasama/totem-models 5.2.2 → 5.3.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/Deal.js +34 -7
  2. package/package.json +1 -1
package/lib/Deal.js CHANGED
@@ -6,6 +6,7 @@ module.exports = function(mongoose, config) {
6
6
 
7
7
  Schema = mongoose.Schema,
8
8
  postFind = require('mongoose-post-find'),
9
+ async = require('async'),
9
10
  _ = require('underscore');
10
11
 
11
12
  var Deal = new Schema({
@@ -106,6 +107,7 @@ module.exports = function(mongoose, config) {
106
107
  .populate('organization', 'name logoUrl website websiteAliases')
107
108
  .populate('messages')
108
109
  .populate('sources.person', 'name avatarUrl title')
110
+ .populate('referrers.person', 'name avatarUrl title')
109
111
  .populate({
110
112
  path: 'documents',
111
113
  match: { customer: config.CUSTOMER_ID }
@@ -116,23 +118,47 @@ module.exports = function(mongoose, config) {
116
118
  };
117
119
 
118
120
  // Get all deals belonging to a customer
119
- Deal.statics.getForCustomer = function (customerId, cb) {
121
+ Deal.statics.getForCustomer = function (customerId, activeCustomerStages, cb) {
120
122
 
121
123
  var self = this;
122
124
 
123
- console.log('Deal.statics.getForCustomer');
124
- console.log('customerId', customerId);
125
+ // todo - fix deep population
126
+ // not sure why chained deepPopulate isn't working (it throws an error)
127
+ // it works to deepPopulate each result instance in parallel
125
128
 
126
129
  self
127
- .find({ 'customer': customerId })
128
- .populate('organization', 'name description logoUrl website websiteAliases')
130
+ .find({ 'customer': customerId, 'stage': { $in: activeCustomerStages } })
131
+ .populate('organization', 'name description logoUrl website websiteAliases chairs')
129
132
  .populate('messages')
130
- .populate('sources.person', 'name avatarUrl')
133
+ .populate('sources.person', 'name avatarUrl title')
134
+ .populate('referrers.person', 'name avatarUrl title')
131
135
  .populate({
132
136
  path: 'documents',
133
137
  match: { customer: customerId }
134
138
  })
135
- .exec(cb);
139
+ // .deepPopulate([
140
+ // 'organization.chairs.first'
141
+ // ], {
142
+ // populate: {
143
+ // 'organization.chairs.first': { select: 'name avatarUrl title doNotDisplay' }
144
+ // }
145
+ // })
146
+ .exec(function(err, deals) {
147
+
148
+ var calls = [];
149
+
150
+ _.each(deals, function(deal) {
151
+ var func = function(callback) {
152
+ deal.deepPopulate('organization.chairs.first', {
153
+ populate: { 'organization.chairs.first': { select: 'name avatarUrl title doNotDisplay' } }
154
+ }, callback);
155
+ };
156
+ calls.push(func);
157
+ });
158
+
159
+ async.parallel(calls, cb);
160
+
161
+ });
136
162
 
137
163
  };
138
164
 
@@ -149,6 +175,7 @@ module.exports = function(mongoose, config) {
149
175
  .populate('organization', 'name logoUrl website websiteAliases')
150
176
  .populate('messages')
151
177
  .populate('sources.person', 'name avatarUrl title')
178
+ .populate('referrers.person', 'name avatarUrl title')
152
179
  .populate({
153
180
  path: 'documents',
154
181
  match: { customer: config.CUSTOMER_ID }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "5.2.2",
3
+ "version": "5.3.1",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",