@dhyasama/totem-models 8.30.0 → 8.31.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.
- package/lib/Financials.js +105 -102
- package/package.json +1 -1
package/lib/Financials.js
CHANGED
|
@@ -293,32 +293,33 @@ module.exports = function(mongoose, config) {
|
|
|
293
293
|
}
|
|
294
294
|
});
|
|
295
295
|
|
|
296
|
+
query.populate('organization', 'name logoUrl');
|
|
297
|
+
query.populate('customer', 'name logoUrl customer.totemUrl');
|
|
298
|
+
|
|
296
299
|
query.exec(function(err, result) {
|
|
297
300
|
|
|
298
301
|
if (err) { return cb(err, null); }
|
|
299
302
|
|
|
300
303
|
var results = [];
|
|
301
304
|
|
|
302
|
-
|
|
303
|
-
snapshots = _.flatten(snapshots);
|
|
305
|
+
_.each(result, function(financial) {
|
|
304
306
|
|
|
305
|
-
|
|
307
|
+
_.each(financial.snapshots, function(snapshot) {
|
|
306
308
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
+
var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
|
|
310
|
+
var hasUnsentSendOnLessThanNow = snapshot.notifications.company.initial.sendOn < now && !snapshot.notifications.company.initial.sentOn;
|
|
309
311
|
|
|
310
|
-
|
|
312
|
+
if(hasRecipients && hasUnsentSendOnLessThanNow) {
|
|
311
313
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
314
|
+
results.push({
|
|
315
|
+
'snapshot': snapshot,
|
|
316
|
+
'customer': snapsot.customer,
|
|
317
|
+
'organization': snapshot.organization
|
|
318
|
+
});
|
|
315
319
|
|
|
316
|
-
|
|
317
|
-
'uuid': snapshot.uuid,
|
|
318
|
-
'recipients': recipients
|
|
319
|
-
});
|
|
320
|
+
}
|
|
320
321
|
|
|
321
|
-
}
|
|
322
|
+
});
|
|
322
323
|
|
|
323
324
|
});
|
|
324
325
|
|
|
@@ -352,36 +353,37 @@ module.exports = function(mongoose, config) {
|
|
|
352
353
|
}
|
|
353
354
|
});
|
|
354
355
|
|
|
356
|
+
query.populate('organization', 'name logoUrl');
|
|
357
|
+
query.populate('customer', 'name logoUrl customer.totemUrl');
|
|
358
|
+
|
|
355
359
|
query.exec(function(err, result) {
|
|
356
360
|
|
|
357
361
|
if (err) { return cb(err, null); }
|
|
358
362
|
|
|
359
363
|
var results = [];
|
|
360
364
|
|
|
361
|
-
|
|
362
|
-
snapshots = _.flatten(snapshots);
|
|
365
|
+
_.each(result, function(financial) {
|
|
363
366
|
|
|
364
|
-
|
|
367
|
+
_.each(financial.snapshots, function(snapshot) {
|
|
365
368
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
369
|
+
var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
|
|
370
|
+
var hasUnsentSendOnLessThanNow = _.find(snapshot.notifications.company.reminders, function(reminder) {
|
|
371
|
+
return reminder.sendOn < now && !reminder.sentOn;
|
|
372
|
+
});
|
|
373
|
+
var hasBeenSubmitted = snapshot.submittedOn;
|
|
374
|
+
var hasBeenRejected = snapshot.rejection;
|
|
372
375
|
|
|
373
|
-
|
|
376
|
+
if(hasRecipients && hasUnsentSendOnLessThanNow && ((!hasBeenSubmitted) || (hasBeenSubmitted && hasBeenRejected))) {
|
|
374
377
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
+
results.push({
|
|
379
|
+
'snapshot': snapshot,
|
|
380
|
+
'customer': snapsot.customer,
|
|
381
|
+
'organization': snapshot.organization
|
|
382
|
+
});
|
|
378
383
|
|
|
379
|
-
|
|
380
|
-
'uuid': snapshot.uuid,
|
|
381
|
-
'recipients': recipients
|
|
382
|
-
});
|
|
384
|
+
}
|
|
383
385
|
|
|
384
|
-
}
|
|
386
|
+
});
|
|
385
387
|
|
|
386
388
|
});
|
|
387
389
|
|
|
@@ -408,36 +410,37 @@ module.exports = function(mongoose, config) {
|
|
|
408
410
|
}
|
|
409
411
|
});
|
|
410
412
|
|
|
413
|
+
query.populate('organization', 'name logoUrl');
|
|
414
|
+
query.populate('customer', 'name logoUrl customer.totemUrl');
|
|
415
|
+
|
|
411
416
|
query.exec(function(err, result) {
|
|
412
417
|
|
|
413
418
|
if (err) { return cb(err, null); }
|
|
414
419
|
|
|
415
420
|
var results = [];
|
|
416
421
|
|
|
417
|
-
|
|
418
|
-
snapshots = _.flatten(snapshots);
|
|
422
|
+
_.each(result, function(financial) {
|
|
419
423
|
|
|
420
|
-
|
|
424
|
+
_.each(financial.snapshots, function(snapshot) {
|
|
421
425
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
426
|
+
var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
|
|
427
|
+
var hasUnsentSendOnLessThanNow = _.find(snapshot.notifications.company.rejections, function(rejection) {
|
|
428
|
+
return rejection.sendOn < now && !rejection.sentOn;
|
|
429
|
+
});
|
|
430
|
+
var hasBeenSubmitted = snapshot.submittedOn;
|
|
431
|
+
var hasBeenRejected = snapshot.rejection;
|
|
428
432
|
|
|
429
|
-
|
|
433
|
+
if(hasRecipients && hasUnsentSendOnLessThanNow && hasBeenSubmitted && hasBeenRejected) {
|
|
430
434
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
435
|
+
results.push({
|
|
436
|
+
'snapshot': snapshot,
|
|
437
|
+
'customer': snapsot.customer,
|
|
438
|
+
'organization': snapshot.organization
|
|
439
|
+
});
|
|
434
440
|
|
|
435
|
-
|
|
436
|
-
'uuid': snapshot.uuid,
|
|
437
|
-
'recipients': recipients
|
|
438
|
-
});
|
|
441
|
+
}
|
|
439
442
|
|
|
440
|
-
}
|
|
443
|
+
});
|
|
441
444
|
|
|
442
445
|
});
|
|
443
446
|
|
|
@@ -463,39 +466,47 @@ module.exports = function(mongoose, config) {
|
|
|
463
466
|
}
|
|
464
467
|
});
|
|
465
468
|
|
|
469
|
+
query.populate('organization', 'name logoUrl');
|
|
470
|
+
query.populate('customer', 'name logoUrl customer.totemUrl');
|
|
471
|
+
query.populate('snapshots.notifications.stakeholders.sendTo.organization', 'name logoUrl customer.totemUrl');
|
|
472
|
+
|
|
466
473
|
query.exec(function(err, result) {
|
|
467
474
|
|
|
468
475
|
if (err) { return cb(err, null); }
|
|
469
476
|
|
|
470
477
|
var results = [];
|
|
471
478
|
|
|
472
|
-
|
|
473
|
-
snapshots = _.flatten(snapshots);
|
|
479
|
+
async.each(result, function(financial, callback1) {
|
|
474
480
|
|
|
475
|
-
|
|
481
|
+
async.each(financial.snapshots, function(snapshot, callback2) {
|
|
476
482
|
|
|
477
|
-
|
|
483
|
+
async.each(snapshot.notifications.stakeholders, function(stakeholder, callback3) {
|
|
478
484
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
485
|
+
var hasEmail = stakeholder.sendTo && stakeholder.sendTo.email;
|
|
486
|
+
var hasOrganization = stakeholder.sendTo && stakeholder.sendTo.organization;
|
|
487
|
+
var hasUnsentSendOnLessThanNow = stakeholder.initial && stakeholder.initial.sendOn < now && !stakeholder.initial.sentOn;
|
|
482
488
|
|
|
483
|
-
|
|
489
|
+
if (!hasEmail || !hasOrganization || !hasUnsentSendOnLessThanNow) return callback3();
|
|
484
490
|
|
|
485
|
-
|
|
491
|
+
Account.findByEmail(stakeholder.sendTo.email, function(err, account) {
|
|
486
492
|
|
|
487
|
-
|
|
488
|
-
|
|
493
|
+
var hasAccount = !_.isEmpty(account);
|
|
494
|
+
var hasAccessToken = !_.isEmpty(account) && account.auth && (account.auth.google && account.auth.google.accessToken) || (account.auth.microsoft && account.auth.microsoft.accessToken);
|
|
489
495
|
|
|
490
|
-
|
|
496
|
+
if (!hasAccount || hasAccessToken) return callback3();
|
|
491
497
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
498
|
+
results.push({
|
|
499
|
+
'snapshot': snapshot,
|
|
500
|
+
'stakeholder': stakeholder,
|
|
501
|
+
'organization': snapshot.organization
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
return callback3();
|
|
496
505
|
|
|
497
|
-
|
|
506
|
+
});
|
|
498
507
|
|
|
508
|
+
}, function (err) {
|
|
509
|
+
return callback2(err, results);
|
|
499
510
|
});
|
|
500
511
|
|
|
501
512
|
}, function (err) {
|
|
@@ -526,41 +537,49 @@ module.exports = function(mongoose, config) {
|
|
|
526
537
|
}
|
|
527
538
|
});
|
|
528
539
|
|
|
540
|
+
query.populate('organization', 'name logoUrl');
|
|
541
|
+
query.populate('customer', 'name logoUrl customer.totemUrl');
|
|
542
|
+
query.populate('snapshots.notifications.stakeholders.sendTo.organization', 'name logoUrl customer.totemUrl');
|
|
543
|
+
|
|
529
544
|
query.exec(function(err, result) {
|
|
530
545
|
|
|
531
546
|
if (err) { return cb(err, null); }
|
|
532
547
|
|
|
533
548
|
var results = [];
|
|
534
549
|
|
|
535
|
-
|
|
536
|
-
snapshots = _.flatten(snapshots);
|
|
550
|
+
async.each(result, function(financial, callback1) {
|
|
537
551
|
|
|
538
|
-
|
|
552
|
+
async.each(financial.snapshots, function(snapshot, callback2) {
|
|
539
553
|
|
|
540
|
-
|
|
554
|
+
async.each(snapshot.notifications.stakeholders, function(stakeholder, callback3) {
|
|
541
555
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
556
|
+
var hasRecipients = stakeholder.sendTo && stakeholder.sendTo.length > 0;
|
|
557
|
+
var hasOrganization = stakeholder.organization;
|
|
558
|
+
var hasUnsentSendOnLessThanNow = _.find(stakeholder.reminders, function(reminder) {
|
|
559
|
+
return reminder.sendOn < now && !reminder.sentOn;
|
|
560
|
+
});
|
|
547
561
|
|
|
548
|
-
|
|
562
|
+
if (!hasRecipients || !hasOrganization || !hasUnsentSendOnLessThanNow) return callback3();
|
|
549
563
|
|
|
550
|
-
|
|
564
|
+
Account.findByEmail(stakeholder.sendTo.email, function(err, account) {
|
|
551
565
|
|
|
552
|
-
|
|
553
|
-
|
|
566
|
+
var hasAccount = !_.isEmpty(account);
|
|
567
|
+
var hasAccessToken = !_.isEmpty(account) && account.auth && (account.auth.google && account.auth.google.accessToken) || (account.auth.microsoft && account.auth.microsoft.accessToken);
|
|
554
568
|
|
|
555
|
-
|
|
569
|
+
if (!hasAccount || hasAccessToken) return callback3();
|
|
556
570
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
571
|
+
results.push({
|
|
572
|
+
'snapshot': snapshot,
|
|
573
|
+
'stakeholder': stakeholder,
|
|
574
|
+
'organization': snapshot.organization
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
return callback3();
|
|
561
578
|
|
|
562
|
-
|
|
579
|
+
});
|
|
563
580
|
|
|
581
|
+
}, function (err) {
|
|
582
|
+
return callback2(err, results);
|
|
564
583
|
});
|
|
565
584
|
|
|
566
585
|
}, function (err) {
|
|
@@ -587,21 +606,6 @@ module.exports = function(mongoose, config) {
|
|
|
587
606
|
|
|
588
607
|
};
|
|
589
608
|
|
|
590
|
-
Financials.statics.getToSend = function getToSend(uuid, cb) {
|
|
591
|
-
|
|
592
|
-
var self = this;
|
|
593
|
-
|
|
594
|
-
var query = self.findOne({
|
|
595
|
-
'snapshots.uuid': uuid
|
|
596
|
-
});
|
|
597
|
-
|
|
598
|
-
query.populate('organization', 'name logoUrl');
|
|
599
|
-
query.populate('customer', 'name logoUrl customer.totemUrl');
|
|
600
|
-
|
|
601
|
-
query.exec(cb);
|
|
602
|
-
|
|
603
|
-
};
|
|
604
|
-
|
|
605
609
|
Financials.statics.removeCustomerFinancials = function removeCustomerFinancials(customerId, cb) {
|
|
606
610
|
|
|
607
611
|
// this is only used to wipe out financials created by the google sheet import process
|
|
@@ -640,7 +644,6 @@ module.exports = function(mongoose, config) {
|
|
|
640
644
|
|
|
641
645
|
};
|
|
642
646
|
|
|
643
|
-
|
|
644
647
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
645
648
|
// HOOKS
|
|
646
649
|
// Pre-save: fired on every document before it is saved
|