@dhyasama/totem-models 6.33.3 → 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 -64
- 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
|
@@ -156,16 +156,7 @@ module.exports = function(mongoose, config) {
|
|
|
156
156
|
match: { customer: config.CUSTOMER_ID }
|
|
157
157
|
})
|
|
158
158
|
.populate('history.account', 'person')
|
|
159
|
-
.exec(
|
|
160
|
-
|
|
161
|
-
if (err) return cb(err, null);
|
|
162
|
-
|
|
163
|
-
deal.deepPopulate('organization.chairs.first', {
|
|
164
|
-
populate: { 'organization.chairs.first': { select: 'name avatarUrl title doNotDisplay' } }
|
|
165
|
-
}, cb);
|
|
166
|
-
|
|
167
|
-
});
|
|
168
|
-
|
|
159
|
+
.exec(cb);
|
|
169
160
|
};
|
|
170
161
|
|
|
171
162
|
Deal.statics.getByIds = function (ids, cb) {
|
|
@@ -179,25 +170,7 @@ module.exports = function(mongoose, config) {
|
|
|
179
170
|
path: 'documents',
|
|
180
171
|
match: { customer: config.CUSTOMER_ID }
|
|
181
172
|
})
|
|
182
|
-
.exec(
|
|
183
|
-
|
|
184
|
-
if (err) return cb(err, null);
|
|
185
|
-
else if (!deals || deals.length == 0) return cb(null, []);
|
|
186
|
-
|
|
187
|
-
var calls = [];
|
|
188
|
-
|
|
189
|
-
_.each(deals, function(deal) {
|
|
190
|
-
var func = function(callback) {
|
|
191
|
-
deal.deepPopulate('organization.chairs.first', {
|
|
192
|
-
populate: { 'organization.chairs.first': { select: 'name avatarUrl title doNotDisplay' } }
|
|
193
|
-
}, callback);
|
|
194
|
-
};
|
|
195
|
-
calls.push(func);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
async.parallel(calls, cb);
|
|
199
|
-
|
|
200
|
-
});
|
|
173
|
+
.exec(cb);
|
|
201
174
|
};
|
|
202
175
|
|
|
203
176
|
// Get all deals belonging to a customer
|
|
@@ -226,33 +199,7 @@ module.exports = function(mongoose, config) {
|
|
|
226
199
|
.populate({
|
|
227
200
|
path: 'documents',
|
|
228
201
|
match: { customer: customerId }
|
|
229
|
-
})
|
|
230
|
-
// .deepPopulate([
|
|
231
|
-
// 'organization.chairs.first'
|
|
232
|
-
// ], {
|
|
233
|
-
// populate: {
|
|
234
|
-
// 'organization.chairs.first': { select: 'name avatarUrl title doNotDisplay' }
|
|
235
|
-
// }
|
|
236
|
-
// })
|
|
237
|
-
.exec(function(err, deals) {
|
|
238
|
-
|
|
239
|
-
if (err) return cb(err, null);
|
|
240
|
-
else if (!deals || deals.length == 0) return cb(null, []);
|
|
241
|
-
|
|
242
|
-
var calls = [];
|
|
243
|
-
|
|
244
|
-
_.each(deals, function(deal) {
|
|
245
|
-
var func = function(callback) {
|
|
246
|
-
deal.deepPopulate('organization.chairs.first', {
|
|
247
|
-
populate: { 'organization.chairs.first': { select: 'name avatarUrl title doNotDisplay' } }
|
|
248
|
-
}, callback);
|
|
249
|
-
};
|
|
250
|
-
calls.push(func);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
async.parallel(calls, cb);
|
|
254
|
-
|
|
255
|
-
});
|
|
202
|
+
}).exec(cb);
|
|
256
203
|
|
|
257
204
|
};
|
|
258
205
|
|
|
@@ -288,14 +235,7 @@ module.exports = function(mongoose, config) {
|
|
|
288
235
|
path: 'documents',
|
|
289
236
|
match: { customer: config.CUSTOMER_ID }
|
|
290
237
|
})
|
|
291
|
-
.exec(
|
|
292
|
-
if(deal && deal.history) {
|
|
293
|
-
deal.deepPopulate('history.account.person', {
|
|
294
|
-
populate: { 'history.account.person': { select: 'name avatarUrl title doNotDisplay' } }
|
|
295
|
-
}, cb);
|
|
296
|
-
}
|
|
297
|
-
else cb(err, deal);
|
|
298
|
-
});
|
|
238
|
+
.exec(cb);
|
|
299
239
|
};
|
|
300
240
|
|
|
301
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
|
});
|