@dhyasama/totem-models 6.29.2 → 6.30.2

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 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/lib/Financials.js CHANGED
@@ -141,17 +141,24 @@ module.exports = function(mongoose, config) {
141
141
 
142
142
  Financials.statics.removeCustomerFinancials = function removeCustomerFinancials(customerId, cb) {
143
143
 
144
+ // this is only used to wipe out financials created by the google sheet import process
145
+ // we do NOT want to delete any financials submitted via forms generated directly from the app
146
+
144
147
  var self = this;
145
148
 
146
149
  self
147
- .remove({customer: customerId})
148
- .exec(cb);
150
+ .update(
151
+ { customer: customerId },
152
+ { $pull : { snapshots: { uuid : null, submittedOn: null, submittedBy: null } } },
153
+ { multi : true }
154
+ ).exec(cb);
149
155
 
150
156
  };
151
157
 
152
158
  Financials.statics.upsert = function upsert(financials, cb) {
153
159
  if (!financials) { return cb(new Error('financials is required'), null); }
154
160
  financials.save(function(err, result) {
161
+ console.log(result);
155
162
  return cb(null, result);
156
163
  });
157
164
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "6.29.2",
3
+ "version": "6.30.2",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
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;