@dhyasama/totem-models 8.63.0 → 8.66.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/Financials.js CHANGED
@@ -138,6 +138,7 @@ module.exports = function(mongoose, config) {
138
138
  initial: {
139
139
  sendOn: { type: Date, required: false },
140
140
  sentOn: { type: Date, required: false },
141
+ sentToQueue: { type: Boolean, default: false },
141
142
  postmarkMessageId: { type: String, trim: true },
142
143
  status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
143
144
  },
@@ -145,6 +146,7 @@ module.exports = function(mongoose, config) {
145
146
  reminders: [{
146
147
  sendOn: { type: Date, required: false },
147
148
  sentOn: { type: Date, required: false },
149
+ sentToQueue: { type: Boolean, default: false },
148
150
  postmarkMessageId: { type: String, trim: true },
149
151
  status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
150
152
  }],
@@ -152,6 +154,7 @@ module.exports = function(mongoose, config) {
152
154
  rejections: [{
153
155
  sendOn: { type: Date, required: false },
154
156
  sentOn: { type: Date, required: false },
157
+ sentToQueue: { type: Boolean, default: false },
155
158
  postmarkMessageId: { type: String, trim: true },
156
159
  status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
157
160
  }]
@@ -169,6 +172,7 @@ module.exports = function(mongoose, config) {
169
172
  initial: {
170
173
  sendOn: { type: Date, required: false },
171
174
  sentOn: { type: Date, required: false },
175
+ sentToQueue: { type: Boolean, default: false },
172
176
  postmarkMessageId: { type: String, trim: true },
173
177
  status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
174
178
  },
@@ -176,6 +180,7 @@ module.exports = function(mongoose, config) {
176
180
  reminders: [{
177
181
  sendOn: { type: Date, required: false },
178
182
  sentOn: { type: Date, required: false },
183
+ sentToQueue: { type: Boolean, default: false },
179
184
  postmarkMessageId: { type: String, trim: true },
180
185
  status: { type: String, enum: [null, 'Sent', 'Bounced', 'Delivered', 'Opened', 'Clicked']}
181
186
  }]
@@ -300,7 +305,8 @@ module.exports = function(mongoose, config) {
300
305
  $elemMatch: {
301
306
  'notifications.company.sendTo': { $gt: [] },
302
307
  'notifications.company.initial.sendOn': { $lte: now },
303
- 'notifications.company.initial.sentOn': null
308
+ 'notifications.company.initial.sentOn': null,
309
+ 'notifications.company.initial.sentToQueue': null,
304
310
  }
305
311
  }
306
312
  });
@@ -315,10 +321,14 @@ module.exports = function(mongoose, config) {
315
321
 
316
322
  _.each(financial.snapshots, function(snapshot) {
317
323
 
318
- var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
319
- var hasUnsentSendOnLessThanNow = snapshot.notifications.company.initial.sendOn < now && !snapshot.notifications.company.initial.sentOn;
324
+ var hasSendTo = snapshot.notifications.company.sendTo.length > 0;
325
+ var hasSendOnLessThanNow = snapshot.notifications.company.initial.sendOn < now;
326
+ var hasSentOn = snapshot.notifications.company.initial.sentOn;
327
+ var hasSentToQueue = snapshot.notifications.company.initial.sentToQueue;
320
328
 
321
- if(hasRecipients && hasUnsentSendOnLessThanNow) {
329
+ var conditions = hasSendTo && hasSendOnLessThanNow && !hasSentOn && !hasSentToQueue;
330
+
331
+ if(conditions) {
322
332
 
323
333
  var recipients = snapshot.notifications.company.sendTo.map(function(sendTo) {
324
334
  return sendTo.email;
@@ -352,6 +362,7 @@ module.exports = function(mongoose, config) {
352
362
  'notifications.company.sendTo': { $gt: [] },
353
363
  'notifications.company.reminders.sendOn': { $lte: now },
354
364
  'notifications.company.reminders.sentOn': null,
365
+ 'notifications.company.reminders.sentToQueue': null,
355
366
  '$or': [
356
367
  {
357
368
  'submittedOn': null,
@@ -375,14 +386,17 @@ module.exports = function(mongoose, config) {
375
386
 
376
387
  _.each(financial.snapshots, function(snapshot) {
377
388
 
378
- var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
379
- var hasUnsentSendOnLessThanNow = _.find(snapshot.notifications.company.reminders, function(reminder) {
380
- return reminder.sendOn < now && !reminder.sentOn;
389
+ var conditions = _.some(snapshot.notifications.company.reminders, function(reminder) {
390
+ var hasSendTo = snapshot.notifications.company.sendTo.length > 0;
391
+ var hasSendOnLessThanNow = reminder.sendOn < now;
392
+ var hasSentOn = reminder.sentOn;
393
+ var hasSentToQueue = reminder.sentToQueue;
394
+ var hasBeenSubmitted = snapshot.submittedOn;
395
+ var hasBeenRejected = snapshot.rejection;
396
+ return hasSendTo && hasSendOnLessThanNow && !hasSentOn && !hasSentToQueue && ((!hasBeenSubmitted) || (hasBeenSubmitted && hasBeenRejected));
381
397
  });
382
- var hasBeenSubmitted = snapshot.submittedOn;
383
- var hasBeenRejected = snapshot.rejection;
384
398
 
385
- if(hasRecipients && hasUnsentSendOnLessThanNow && ((!hasBeenSubmitted) || (hasBeenSubmitted && hasBeenRejected))) {
399
+ if(conditions) {
386
400
 
387
401
  var recipients = snapshot.notifications.company.sendTo.map(function(sendTo) {
388
402
  return sendTo.email;
@@ -416,6 +430,7 @@ module.exports = function(mongoose, config) {
416
430
  'notifications.company.sendTo': { $gt: [] },
417
431
  'notifications.company.rejections.sendOn': { $lte: now },
418
432
  'notifications.company.rejections.sentOn': null,
433
+ 'notifications.company.rejections.sentToQueue': null,
419
434
  'submittedOn': { $ne: null },
420
435
  'rejection': { $ne: null }
421
436
  }
@@ -432,14 +447,17 @@ module.exports = function(mongoose, config) {
432
447
 
433
448
  _.each(financial.snapshots, function(snapshot) {
434
449
 
435
- var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
436
- var hasUnsentSendOnLessThanNow = _.find(snapshot.notifications.company.rejections, function(rejection) {
437
- return rejection.sendOn < now && !rejection.sentOn;
450
+ var conditions = _.some(snapshot.notifications.company.rejections, function(rejection) {
451
+ var hasSendTo = snapshot.notifications.company.sendTo.length > 0;
452
+ var hasSendOnLessThanNow = rejection.sendOn < now;
453
+ var hasSentOn = rejection.sentOn;
454
+ var hasSentToQueue = rejection.sentToQueue;
455
+ var hasBeenSubmitted = snapshot.submittedOn;
456
+ var hasBeenRejected = snapshot.rejection;
457
+ return hasSendTo && hasSendOnLessThanNow && !hasSentOn && !hasSentToQueue && hasBeenSubmitted && hasBeenRejected;
438
458
  });
439
- var hasBeenSubmitted = snapshot.submittedOn;
440
- var hasBeenRejected = snapshot.rejection;
441
459
 
442
- if(hasRecipients && hasUnsentSendOnLessThanNow && hasBeenSubmitted && hasBeenRejected) {
460
+ if(conditions) {
443
461
 
444
462
  var recipients = snapshot.notifications.company.sendTo.map(function(sendTo) {
445
463
  return sendTo.email;
@@ -473,7 +491,8 @@ module.exports = function(mongoose, config) {
473
491
  'notifications.stakeholders.sendTo.email': { $ne: null },
474
492
  'notifications.stakeholders.sendTo.organization': { $ne: null },
475
493
  'notifications.stakeholders.initial.sendOn': { $lte: now },
476
- 'notifications.stakeholders.initial.sentOn': null
494
+ 'notifications.stakeholders.initial.sentOn': null,
495
+ 'notifications.stakeholders.initial.sentToQueue': null,
477
496
  }
478
497
  }
479
498
  });
@@ -490,11 +509,15 @@ module.exports = function(mongoose, config) {
490
509
 
491
510
  _.each(snapshot.notifications.stakeholders, function(stakeholder) {
492
511
 
493
- var hasEmail = stakeholder.sendTo && stakeholder.sendTo.email;
512
+ var hasSendTo = stakeholder.sendTo && stakeholder.sendTo.email;
494
513
  var hasOrganization = stakeholder.sendTo && stakeholder.sendTo.organization;
495
- var hasUnsentSendOnLessThanNow = stakeholder.initial && stakeholder.initial.sendOn < now && !stakeholder.initial.sentOn;
514
+ var hasSendOnLessThanNow = stakeholder.initial && stakeholder.initial.sendOn < now;
515
+ var hasSentOn = stakeholder.initial && stakeholder.initial.sentOn;
516
+ var hasSentToQueue = stakeholder.initial && stakeholder.initial.sentToQueue;
517
+
518
+ var conditions = hasSendTo && hasOrganization && hasSendOnLessThanNow && !hasSendTo && !hasSentToQueue;
496
519
 
497
- if(hasEmail && hasOrganization && hasUnsentSendOnLessThanNow) {
520
+ if(conditions) {
498
521
 
499
522
  results.push({
500
523
  'uuid': snapshot.uuid,
@@ -526,7 +549,8 @@ module.exports = function(mongoose, config) {
526
549
  'notifications.stakeholders.sendTo.email': { $ne: null },
527
550
  'notifications.stakeholders.sendTo.organization': { $ne: null },
528
551
  'notifications.stakeholders.reminders.sendOn': { $lte: now },
529
- 'notifications.stakeholders.reminders.sentOn': null
552
+ 'notifications.stakeholders.reminders.sentOn': null,
553
+ 'notifications.stakeholders.reminders.sentToQueue': null
530
554
  }
531
555
  }
532
556
  });
@@ -543,17 +567,16 @@ module.exports = function(mongoose, config) {
543
567
 
544
568
  _.each(snapshot.notifications.stakeholders, function(stakeholder) {
545
569
 
546
- var hasEmail = stakeholder.sendTo && stakeholder.sendTo.email;
547
- var hasOrganization = stakeholder.sendTo && stakeholder.sendTo.organization;
548
- var hasUnsentSendOnLessThanNow = _.find(stakeholder.reminders, function(reminder) {
549
- return reminder.sendOn < now && !reminder.sentOn;
550
- });
551
- var hasNotClickedInitial = stakeholder.initial && stakeholder.initial.status != 'Clicked';
552
- var hasNotClickedReminder = _.every(stakeholder.reminders, function(reminder) {
553
- return reminder.status != 'Clicked';
570
+ var conditions = _.some(stakeholder.reminders, function(reminder) {
571
+ var hasSendTo = stakeholder.sendTo && stakeholder.sendTo.email;
572
+ var hasOrganization = stakeholder.sendTo && stakeholder.sendTo.organization;
573
+ var hasSendOnLessThanNow = reminder.sendOn < now;
574
+ var hasSentOn = reminder.sentOn;
575
+ var hasSentToQueue = reminder.sentToQueue;
576
+ return hasSendTo && hasOrganization && hasSendOnLessThanNow && !hasSentOn && !hasSentToQueue;
554
577
  });
555
578
 
556
- if(hasEmail && hasOrganization && hasUnsentSendOnLessThanNow && hasNotClickedInitial && hasNotClickedReminder) {
579
+ if(conditions) {
557
580
 
558
581
  results.push({
559
582
  'uuid': snapshot.uuid,
@@ -201,7 +201,7 @@ module.exports = function(mongoose, config) {
201
201
  _id: false,
202
202
  key: { type: String, trim: true },
203
203
  condition: { type: String, enum: [null, 'equals', 'doesNotEqual', 'contains', 'doesNotContain', 'lessThan', 'greaterThan']},
204
- value: { type: String, trim: true },
204
+ values: [{ type: String, trim: true }],
205
205
  }],
206
206
  sort: {
207
207
  by: { type: String, trim: true },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "8.63.0",
3
+ "version": "8.66.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",