@dhyasama/totem-models 5.3.0 → 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.
- package/lib/Deal.js +27 -3
- 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({
|
|
@@ -121,8 +122,9 @@ module.exports = function(mongoose, config) {
|
|
|
121
122
|
|
|
122
123
|
var self = this;
|
|
123
124
|
|
|
124
|
-
|
|
125
|
-
|
|
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
|
|
126
128
|
|
|
127
129
|
self
|
|
128
130
|
.find({ 'customer': customerId, 'stage': { $in: activeCustomerStages } })
|
|
@@ -134,7 +136,29 @@ module.exports = function(mongoose, config) {
|
|
|
134
136
|
path: 'documents',
|
|
135
137
|
match: { customer: customerId }
|
|
136
138
|
})
|
|
137
|
-
.
|
|
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
|
+
});
|
|
138
162
|
|
|
139
163
|
};
|
|
140
164
|
|