@dhyasama/totem-models 7.51.0 → 7.52.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.
Files changed (2) hide show
  1. package/lib/Financials.js +97 -16
  2. package/package.json +1 -1
package/lib/Financials.js CHANGED
@@ -127,27 +127,26 @@ module.exports = function(mongoose, config) {
127
127
  name: { type: String, trim: true }
128
128
  }],
129
129
 
130
- sendOn: [{
130
+ initial: {
131
131
  sendOn: { type: Date, required: false },
132
132
  sentOn: { type: Date, required: false },
133
133
  postmarkMessageId: { type: String, trim: true },
134
134
  status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
135
- }],
135
+ },
136
136
 
137
- // INITIAL AND REMINDER BEING DELETED
138
- initial: {
137
+ reminders: [{
139
138
  sendOn: { type: Date, required: false },
140
139
  sentOn: { type: Date, required: false },
141
140
  postmarkMessageId: { type: String, trim: true },
142
141
  status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
143
- },
142
+ }],
144
143
 
145
- reminder: {
144
+ rejections: [{
146
145
  sendOn: { type: Date, required: false },
147
146
  sentOn: { type: Date, required: false },
148
147
  postmarkMessageId: { type: String, trim: true },
149
- status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
150
- },
148
+ status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
149
+ }]
151
150
 
152
151
  },
153
152
 
@@ -231,7 +230,89 @@ module.exports = function(mongoose, config) {
231
230
 
232
231
  };
233
232
 
234
- Financials.statics.getUUIDsToSend = function getUUIDsToSend(cb) {
233
+ Financials.statics.getInitialUUIDsToSend = function getInitialUUIDsToSend(cb) {
234
+
235
+ var self = this;
236
+ var now = new Date();
237
+
238
+ var query = self.find({
239
+ 'snapshots': {
240
+ $elemMatch: {
241
+ 'notifications.company.sendTo': { $gt: [] },
242
+ 'notifications.company.initial.sendOn': { $lte: now },
243
+ 'notifications.company.initial.sentOn': null
244
+ }
245
+ }
246
+ });
247
+
248
+ query.exec(function(err, result) {
249
+
250
+ if (err) { return cb(err, null); }
251
+
252
+ var snapshots = _.pluck(result || [], 'snapshots');
253
+
254
+ snapshots = _.flatten(snapshots);
255
+
256
+ snapshots = _.filter(snapshots, function(snapshot) {
257
+
258
+ var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
259
+ var hasSendOnLessThanNow = snapshot.notifications.company.initial.sendOn < now;
260
+ var hasNotBeenSentTo = !snapshot.notifications.company.initial.sentOn;
261
+
262
+ return hasRecipients && hasSendOnLessThanNow && hasNotBeenSentTo;
263
+
264
+ });
265
+
266
+ return cb(null, _.pluck(snapshots, 'uuid'));
267
+
268
+ });
269
+
270
+ };
271
+
272
+ Financials.statics.getReminderUUIDsToSend = function getReminderUUIDsToSend(cb) {
273
+
274
+ var self = this;
275
+ var now = new Date();
276
+
277
+ var query = self.find({
278
+ 'snapshots': {
279
+ $elemMatch: {
280
+ 'notifications.company.sendTo': { $gt: [] },
281
+ 'notifications.company.reminders.sendOn': { $lte: now },
282
+ 'notifications.company.reminders.sentOn': null
283
+ }
284
+ }
285
+ });
286
+
287
+ query.exec(function(err, result) {
288
+
289
+ if (err) { return cb(err, null); }
290
+
291
+ var snapshots = _.pluck(result || [], 'snapshots');
292
+
293
+ snapshots = _.flatten(snapshots);
294
+
295
+ snapshots = _.filter(snapshots, function(snapshot) {
296
+
297
+ var sendOnLessThanNow = _.find(snapshot.notifications.company.reminders, function(reminder) {
298
+ return reminder.sendOn < now;
299
+ });
300
+
301
+ var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
302
+ var hasSendOnLessThanNow = !_.isEmpty(sendOnLessThanNow);
303
+ var hasNotBeenSentTo = !sendOnLessThanNow.sentOn;
304
+
305
+ return hasRecipients && hasSendOnLessThanNow && hasNotBeenSentTo;
306
+
307
+ });
308
+
309
+ return cb(null, _.pluck(snapshots, 'uuid'));
310
+
311
+ });
312
+
313
+ };
314
+
315
+ Financials.statics.getRejectionUUIDsToSend = function getRejectionUUIDsToSend(cb) {
235
316
 
236
317
  var self = this;
237
318
  var now = new Date();
@@ -240,8 +321,8 @@ module.exports = function(mongoose, config) {
240
321
  'snapshots': {
241
322
  $elemMatch: {
242
323
  'notifications.company.sendTo': { $gt: [] },
243
- 'notifications.company.sendOn.sendOn': { $lte: now },
244
- 'notifications.company.sendOn.sentOn': null
324
+ 'notifications.company.rejections.sendOn': { $lte: now },
325
+ 'notifications.company.rejections.sentOn': null
245
326
  }
246
327
  }
247
328
  });
@@ -256,15 +337,15 @@ module.exports = function(mongoose, config) {
256
337
 
257
338
  snapshots = _.filter(snapshots, function(snapshot) {
258
339
 
259
- var sendOnsLessThanNow = _.filter(snapshot.notifications.company.sendOn, function(sendOn) {
260
- return sendOn.sendOn < now;
340
+ var sendOnLessThanNow = _.find(snapshot.notifications.company.rejections, function(rejection) {
341
+ return rejection.sendOn < now;
261
342
  });
262
343
 
263
344
  var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
264
- var hasSendOnLessThanNow = !_.isEmpty(sendOnsLessThanNow);
265
- var hasSendOnNotSent = _.some(sendOnsLessThanNow, function(s) { return s.sentOn ? false : true; });
345
+ var hasSendOnLessThanNow = !_.isEmpty(sendOnLessThanNow);
346
+ var hasNotBeenSentTo = !sendOnLessThanNow.sentOn;
266
347
 
267
- return hasRecipients && hasSendOnLessThanNow && hasSendOnNotSent;
348
+ return hasRecipients && hasSendOnLessThanNow && hasNotBeenSentTo;
268
349
 
269
350
  });
270
351
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "7.51.0",
3
+ "version": "7.52.1",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",