@dhyasama/totem-models 7.50.1 → 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 +136 -8
- 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,6 +230,135 @@ module.exports = function(mongoose, config) {
|
|
|
231
230
|
|
|
232
231
|
};
|
|
233
232
|
|
|
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) {
|
|
320
|
+
|
|
321
|
+
var self = this;
|
|
322
|
+
var now = new Date();
|
|
323
|
+
|
|
324
|
+
var query = self.find({
|
|
325
|
+
'snapshots': {
|
|
326
|
+
$elemMatch: {
|
|
327
|
+
'notifications.company.sendTo': { $gt: [] },
|
|
328
|
+
'notifications.company.rejections.sendOn': { $lte: now },
|
|
329
|
+
'notifications.company.rejections.sentOn': null
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
query.exec(function(err, result) {
|
|
335
|
+
|
|
336
|
+
if (err) { return cb(err, null); }
|
|
337
|
+
|
|
338
|
+
var snapshots = _.pluck(result || [], 'snapshots');
|
|
339
|
+
|
|
340
|
+
snapshots = _.flatten(snapshots);
|
|
341
|
+
|
|
342
|
+
snapshots = _.filter(snapshots, function(snapshot) {
|
|
343
|
+
|
|
344
|
+
var sendOnLessThanNow = _.find(snapshot.notifications.company.rejections, function(rejection) {
|
|
345
|
+
return rejection.sendOn < now;
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
|
|
349
|
+
var hasSendOnLessThanNow = !_.isEmpty(sendOnLessThanNow);
|
|
350
|
+
var hasNotBeenSentTo = !sendOnLessThanNow.sentOn;
|
|
351
|
+
|
|
352
|
+
return hasRecipients && hasSendOnLessThanNow && hasNotBeenSentTo;
|
|
353
|
+
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
return cb(null, _.pluck(snapshots, 'uuid'));
|
|
357
|
+
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
};
|
|
361
|
+
|
|
234
362
|
Financials.statics.getForCustomer = function getForCustomer(customerId, cb) {
|
|
235
363
|
|
|
236
364
|
var self = this;
|