@dhyasama/totem-models 7.50.1 → 7.51.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 +43 -0
- package/package.json +1 -1
package/lib/Financials.js
CHANGED
|
@@ -231,6 +231,49 @@ module.exports = function(mongoose, config) {
|
|
|
231
231
|
|
|
232
232
|
};
|
|
233
233
|
|
|
234
|
+
Financials.statics.getUUIDsToSend = function getUUIDsToSend(cb) {
|
|
235
|
+
|
|
236
|
+
var self = this;
|
|
237
|
+
var now = new Date();
|
|
238
|
+
|
|
239
|
+
var query = self.find({
|
|
240
|
+
'snapshots': {
|
|
241
|
+
$elemMatch: {
|
|
242
|
+
'notifications.company.sendTo': { $gt: [] },
|
|
243
|
+
'notifications.company.sendOn.sendOn': { $lte: now },
|
|
244
|
+
'notifications.company.sendOn.sentOn': null
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
query.exec(function(err, result) {
|
|
250
|
+
|
|
251
|
+
if (err) { return cb(err, null); }
|
|
252
|
+
|
|
253
|
+
var snapshots = _.pluck(result || [], 'snapshots');
|
|
254
|
+
|
|
255
|
+
snapshots = _.flatten(snapshots);
|
|
256
|
+
|
|
257
|
+
snapshots = _.filter(snapshots, function(snapshot) {
|
|
258
|
+
|
|
259
|
+
var sendOnsLessThanNow = _.filter(snapshot.notifications.company.sendOn, function(sendOn) {
|
|
260
|
+
return sendOn.sendOn < now;
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
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; });
|
|
266
|
+
|
|
267
|
+
return hasRecipients && hasSendOnLessThanNow && hasSendOnNotSent;
|
|
268
|
+
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
return cb(null, _.pluck(snapshots, 'uuid'));
|
|
272
|
+
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
};
|
|
276
|
+
|
|
234
277
|
Financials.statics.getForCustomer = function getForCustomer(customerId, cb) {
|
|
235
278
|
|
|
236
279
|
var self = this;
|