@dhyasama/totem-models 6.29.2 → 6.30.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 +4 -1
- package/package.json +1 -1
- package/test/Deal.js +24 -0
package/lib/Deal.js
CHANGED
|
@@ -203,8 +203,11 @@ module.exports = function(mongoose, config) {
|
|
|
203
203
|
|
|
204
204
|
options = options || {};
|
|
205
205
|
|
|
206
|
+
// { history: { $elemMatch: { timestamp: { $gte: ISODate("2019-01-03T20:45:14.406+0000") } } } }
|
|
207
|
+
|
|
206
208
|
var terms = { 'customer': customerId };
|
|
207
|
-
if (options.stage) terms['stage'] = { $in: options.stage };
|
|
209
|
+
if (options.stage) { terms['stage'] = { $in: options.stage }; }
|
|
210
|
+
if (options.since) { terms['history'] = { $elemMatch: { timestamp: { $gte: options.since } } }; }
|
|
208
211
|
|
|
209
212
|
self
|
|
210
213
|
.find(terms)
|
package/package.json
CHANGED
package/test/Deal.js
CHANGED
|
@@ -15,6 +15,7 @@ var org;
|
|
|
15
15
|
var customer;
|
|
16
16
|
var dealId;
|
|
17
17
|
var account;
|
|
18
|
+
var timestamps = [];
|
|
18
19
|
|
|
19
20
|
describe('Deal', function() {
|
|
20
21
|
|
|
@@ -217,10 +218,18 @@ describe('Deal', function() {
|
|
|
217
218
|
should.exist(result);
|
|
218
219
|
|
|
219
220
|
Deal.getForCustomer(config.CUSTOMER_ID, {}, function(err, result) {
|
|
221
|
+
|
|
220
222
|
should.not.exist(err);
|
|
221
223
|
should.exist(result)
|
|
224
|
+
|
|
222
225
|
result.length.should.equal(2);
|
|
226
|
+
|
|
227
|
+
timestamps = _.pluck(result[0].history, 'timestamp');
|
|
228
|
+
timestamps = timestamps.concat(_.pluck(result[0].history, 'timestamp'));
|
|
229
|
+
timestamps = _.sortBy(timestamps, function(ts) { return - (new Date(ts)); });
|
|
230
|
+
|
|
223
231
|
return done();
|
|
232
|
+
|
|
224
233
|
});
|
|
225
234
|
|
|
226
235
|
});
|
|
@@ -229,6 +238,21 @@ describe('Deal', function() {
|
|
|
229
238
|
|
|
230
239
|
});
|
|
231
240
|
|
|
241
|
+
it('gets new deals for a customer', function(done) {
|
|
242
|
+
|
|
243
|
+
Deal.getForCustomer(config.CUSTOMER_ID, { since: timestamps[0] }, function(err, result) {
|
|
244
|
+
|
|
245
|
+
should.not.exist(err);
|
|
246
|
+
should.exist(result);
|
|
247
|
+
|
|
248
|
+
result.length.should.be.greaterThan(0);
|
|
249
|
+
|
|
250
|
+
return done();
|
|
251
|
+
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
});
|
|
255
|
+
|
|
232
256
|
it('gets all deals', function(done) {
|
|
233
257
|
|
|
234
258
|
var temp = config.CUSTOMER_ID;
|