@dhyasama/totem-models 7.51.0 → 7.52.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 +101 -16
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,93 @@ module.exports = function(mongoose, config) {
|
|
|
231
230
|
|
|
232
231
|
};
|
|
233
232
|
|
|
234
|
-
Financials.statics.
|
|
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
|
+
//console.log(hasRecipients);
|
|
263
|
+
//console.log(hasSendOnLessThanNow);
|
|
264
|
+
//console.log(hasNotBeenSentTo);
|
|
265
|
+
|
|
266
|
+
return hasRecipients && hasSendOnLessThanNow && hasNotBeenSentTo;
|
|
267
|
+
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
return cb(null, _.pluck(snapshots, 'uuid'));
|
|
271
|
+
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
Financials.statics.getReminderUUIDsToSend = function getReminderUUIDsToSend(cb) {
|
|
277
|
+
|
|
278
|
+
var self = this;
|
|
279
|
+
var now = new Date();
|
|
280
|
+
|
|
281
|
+
var query = self.find({
|
|
282
|
+
'snapshots': {
|
|
283
|
+
$elemMatch: {
|
|
284
|
+
'notifications.company.sendTo': { $gt: [] },
|
|
285
|
+
'notifications.company.reminders.sendOn': { $lte: now },
|
|
286
|
+
'notifications.company.reminders.sentOn': null
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
query.exec(function(err, result) {
|
|
292
|
+
|
|
293
|
+
if (err) { return cb(err, null); }
|
|
294
|
+
|
|
295
|
+
var snapshots = _.pluck(result || [], 'snapshots');
|
|
296
|
+
|
|
297
|
+
snapshots = _.flatten(snapshots);
|
|
298
|
+
|
|
299
|
+
snapshots = _.filter(snapshots, function(snapshot) {
|
|
300
|
+
|
|
301
|
+
var sendOnLessThanNow = _.find(snapshot.notifications.company.reminders, function(reminder) {
|
|
302
|
+
return reminder.sendOn < now;
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
|
|
306
|
+
var hasSendOnLessThanNow = !_.isEmpty(sendOnLessThanNow);
|
|
307
|
+
var hasNotBeenSentTo = !sendOnLessThanNow.sentOn;
|
|
308
|
+
|
|
309
|
+
return hasRecipients && hasSendOnLessThanNow && hasNotBeenSentTo;
|
|
310
|
+
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
return cb(null, _.pluck(snapshots, 'uuid'));
|
|
314
|
+
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
Financials.statics.getRejectionUUIDsToSend = function getRejectionUUIDsToSend(cb) {
|
|
235
320
|
|
|
236
321
|
var self = this;
|
|
237
322
|
var now = new Date();
|
|
@@ -240,8 +325,8 @@ module.exports = function(mongoose, config) {
|
|
|
240
325
|
'snapshots': {
|
|
241
326
|
$elemMatch: {
|
|
242
327
|
'notifications.company.sendTo': { $gt: [] },
|
|
243
|
-
'notifications.company.
|
|
244
|
-
'notifications.company.
|
|
328
|
+
'notifications.company.rejections.sendOn': { $lte: now },
|
|
329
|
+
'notifications.company.rejections.sentOn': null
|
|
245
330
|
}
|
|
246
331
|
}
|
|
247
332
|
});
|
|
@@ -256,15 +341,15 @@ module.exports = function(mongoose, config) {
|
|
|
256
341
|
|
|
257
342
|
snapshots = _.filter(snapshots, function(snapshot) {
|
|
258
343
|
|
|
259
|
-
var
|
|
260
|
-
return
|
|
344
|
+
var sendOnLessThanNow = _.find(snapshot.notifications.company.rejections, function(rejection) {
|
|
345
|
+
return rejection.sendOn < now;
|
|
261
346
|
});
|
|
262
347
|
|
|
263
348
|
var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
|
|
264
|
-
var hasSendOnLessThanNow = !_.isEmpty(
|
|
265
|
-
var
|
|
349
|
+
var hasSendOnLessThanNow = !_.isEmpty(sendOnLessThanNow);
|
|
350
|
+
var hasNotBeenSentTo = !sendOnLessThanNow.sentOn;
|
|
266
351
|
|
|
267
|
-
return hasRecipients && hasSendOnLessThanNow &&
|
|
352
|
+
return hasRecipients && hasSendOnLessThanNow && hasNotBeenSentTo;
|
|
268
353
|
|
|
269
354
|
});
|
|
270
355
|
|