@dhyasama/totem-models 6.33.2 → 6.34.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/Account.js +6 -0
- package/lib/Deal.js +4 -56
- package/package.json +1 -1
- package/test/Account.js +30 -1
package/lib/Account.js
CHANGED
|
@@ -127,6 +127,12 @@ module.exports = function(mongoose, config) {
|
|
|
127
127
|
.exec(cb);
|
|
128
128
|
};
|
|
129
129
|
|
|
130
|
+
Account.statics.getForCustomer = function (customerId, cb) {
|
|
131
|
+
this
|
|
132
|
+
.find({ 'org': customerId })
|
|
133
|
+
.exec(cb);
|
|
134
|
+
};
|
|
135
|
+
|
|
130
136
|
Account.statics.listGoogleAccounts = function(cb) {
|
|
131
137
|
|
|
132
138
|
this
|
package/lib/Deal.js
CHANGED
|
@@ -147,7 +147,7 @@ module.exports = function(mongoose, config) {
|
|
|
147
147
|
'_id': id,
|
|
148
148
|
'customer': config.CUSTOMER_ID
|
|
149
149
|
})
|
|
150
|
-
.populate('organization', 'name logoUrl website websiteAliases')
|
|
150
|
+
.populate('organization', 'name description logoUrl website websiteAliases chairs')
|
|
151
151
|
.populate('messages')
|
|
152
152
|
.populate('source.person', 'name avatarUrl title')
|
|
153
153
|
.populate('referrer.person', 'name avatarUrl title')
|
|
@@ -157,7 +157,6 @@ module.exports = function(mongoose, config) {
|
|
|
157
157
|
})
|
|
158
158
|
.populate('history.account', 'person')
|
|
159
159
|
.exec(cb);
|
|
160
|
-
|
|
161
160
|
};
|
|
162
161
|
|
|
163
162
|
Deal.statics.getByIds = function (ids, cb) {
|
|
@@ -171,25 +170,7 @@ module.exports = function(mongoose, config) {
|
|
|
171
170
|
path: 'documents',
|
|
172
171
|
match: { customer: config.CUSTOMER_ID }
|
|
173
172
|
})
|
|
174
|
-
.exec(
|
|
175
|
-
|
|
176
|
-
if (err) return cb(err, null);
|
|
177
|
-
else if (!deals || deals.length == 0) return cb(null, []);
|
|
178
|
-
|
|
179
|
-
var calls = [];
|
|
180
|
-
|
|
181
|
-
_.each(deals, function(deal) {
|
|
182
|
-
var func = function(callback) {
|
|
183
|
-
deal.deepPopulate('organization.chairs.first', {
|
|
184
|
-
populate: { 'organization.chairs.first': { select: 'name avatarUrl title doNotDisplay' } }
|
|
185
|
-
}, callback);
|
|
186
|
-
};
|
|
187
|
-
calls.push(func);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
async.parallel(calls, cb);
|
|
191
|
-
|
|
192
|
-
});
|
|
173
|
+
.exec(cb);
|
|
193
174
|
};
|
|
194
175
|
|
|
195
176
|
// Get all deals belonging to a customer
|
|
@@ -218,33 +199,7 @@ module.exports = function(mongoose, config) {
|
|
|
218
199
|
.populate({
|
|
219
200
|
path: 'documents',
|
|
220
201
|
match: { customer: customerId }
|
|
221
|
-
})
|
|
222
|
-
// .deepPopulate([
|
|
223
|
-
// 'organization.chairs.first'
|
|
224
|
-
// ], {
|
|
225
|
-
// populate: {
|
|
226
|
-
// 'organization.chairs.first': { select: 'name avatarUrl title doNotDisplay' }
|
|
227
|
-
// }
|
|
228
|
-
// })
|
|
229
|
-
.exec(function(err, deals) {
|
|
230
|
-
|
|
231
|
-
if (err) return cb(err, null);
|
|
232
|
-
else if (!deals || deals.length == 0) return cb(null, []);
|
|
233
|
-
|
|
234
|
-
var calls = [];
|
|
235
|
-
|
|
236
|
-
_.each(deals, function(deal) {
|
|
237
|
-
var func = function(callback) {
|
|
238
|
-
deal.deepPopulate('organization.chairs.first', {
|
|
239
|
-
populate: { 'organization.chairs.first': { select: 'name avatarUrl title doNotDisplay' } }
|
|
240
|
-
}, callback);
|
|
241
|
-
};
|
|
242
|
-
calls.push(func);
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
async.parallel(calls, cb);
|
|
246
|
-
|
|
247
|
-
});
|
|
202
|
+
}).exec(cb);
|
|
248
203
|
|
|
249
204
|
};
|
|
250
205
|
|
|
@@ -280,14 +235,7 @@ module.exports = function(mongoose, config) {
|
|
|
280
235
|
path: 'documents',
|
|
281
236
|
match: { customer: config.CUSTOMER_ID }
|
|
282
237
|
})
|
|
283
|
-
.exec(
|
|
284
|
-
if(deal && deal.history) {
|
|
285
|
-
deal.deepPopulate('history.account.person', {
|
|
286
|
-
populate: { 'history.account.person': { select: 'name avatarUrl title doNotDisplay' } }
|
|
287
|
-
}, cb);
|
|
288
|
-
}
|
|
289
|
-
else cb(err, deal);
|
|
290
|
-
});
|
|
238
|
+
.exec(cb);
|
|
291
239
|
};
|
|
292
240
|
|
|
293
241
|
Deal.statics.modifyById = function(id, update, cb) {
|
package/package.json
CHANGED
package/test/Account.js
CHANGED
|
@@ -10,11 +10,12 @@ var
|
|
|
10
10
|
Crypto = require('@dhyasama/ffvc-crypto'),
|
|
11
11
|
crypto = new Crypto({'key': config.crypto.key}),
|
|
12
12
|
Account = mongoose.model('Account'),
|
|
13
|
+
Organization = mongoose.model('Organization'),
|
|
13
14
|
Person = mongoose.model('Person'),
|
|
14
15
|
person = new Person();
|
|
15
16
|
|
|
16
17
|
var accountid;
|
|
17
|
-
|
|
18
|
+
var customer;
|
|
18
19
|
|
|
19
20
|
describe('Account', function() {
|
|
20
21
|
|
|
@@ -27,6 +28,23 @@ describe('Account', function() {
|
|
|
27
28
|
clearDB(done);
|
|
28
29
|
});
|
|
29
30
|
|
|
31
|
+
before(function(done) {
|
|
32
|
+
|
|
33
|
+
customer = new Organization();
|
|
34
|
+
customer.name = 'Fudgesicle';
|
|
35
|
+
customer.slug = 'fudgesicle';
|
|
36
|
+
customer.website = 'yum.io';
|
|
37
|
+
customer.deleted = false;
|
|
38
|
+
customer.aliases.push('sicle');
|
|
39
|
+
customer.crunchbase.uuid = 'jkl';
|
|
40
|
+
customer.crunchbase.url = 'jkl';
|
|
41
|
+
|
|
42
|
+
Organization.upsert(customer, 'test-user', function (err, no5) {
|
|
43
|
+
done();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
});
|
|
47
|
+
|
|
30
48
|
it('creates an account', function(done) {
|
|
31
49
|
|
|
32
50
|
person.name.first = 'George';
|
|
@@ -48,6 +66,7 @@ describe('Account', function() {
|
|
|
48
66
|
account.email = 'test@totemvc.com';
|
|
49
67
|
account.person = newPerson;
|
|
50
68
|
account.active = true;
|
|
69
|
+
account.customer = customer;
|
|
51
70
|
|
|
52
71
|
Account.upsert(account, function(err, updatedAccount) {
|
|
53
72
|
should.not.exist(err);
|
|
@@ -113,4 +132,14 @@ describe('Account', function() {
|
|
|
113
132
|
|
|
114
133
|
});
|
|
115
134
|
|
|
135
|
+
it('lists accounts for customer', function(done) {
|
|
136
|
+
|
|
137
|
+
Account.getForCustomer(customer._id, function(err, result) {
|
|
138
|
+
should.not.exist(err);
|
|
139
|
+
should.exist(result);
|
|
140
|
+
done();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
});
|
|
144
|
+
|
|
116
145
|
});
|