@dhyasama/totem-models 11.18.0 → 11.20.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
@@ -901,14 +901,31 @@ module.exports = function(mongoose, config) {
901
901
 
902
902
  };
903
903
 
904
- Financials.statics.getForCustomer = function getForCustomer(customerId, cb) {
905
-
904
+ Financials.statics.getForCustomer = function getForCustomer(customerId, options, cb) {
905
+
906
906
  var self = this;
907
907
 
908
908
  var query = self.find({
909
909
  'customer': customerId
910
910
  });
911
911
 
912
+ var dateRangeQuery = {};
913
+ if (options.startDate) {
914
+ var startDate = new Date(options.startDate);
915
+ dateRangeQuery['$gte'] = startDate;
916
+ }
917
+
918
+ if (options.endDate) {
919
+ var endDate = new Date(options.endDate);
920
+ dateRangeQuery['$lte'] = endDate;
921
+ }
922
+
923
+ if (options.startDate || options.endDate) {
924
+ query.where('snapshots').elemMatch({
925
+ submittedOn: dateRangeQuery
926
+ });
927
+ }
928
+
912
929
  query.exec(cb);
913
930
 
914
931
  };
@@ -1703,6 +1703,51 @@ module.exports = function(mongoose, config) {
1703
1703
 
1704
1704
  };
1705
1705
 
1706
+ Organization.statics.getValuationsForOrgs = function getValuationForOrgs(orgIds, customerId, startDate, endDate, options, cb) {
1707
+
1708
+ const self = this;
1709
+
1710
+ if (!cb) {
1711
+ throw new Error('cb is required');
1712
+ }
1713
+ if (!orgIds) {
1714
+ return cb(new Error('orgIds is required'), null);
1715
+ }
1716
+ if (!options) {
1717
+ return cb(new Error('options is required'), null);
1718
+ }
1719
+ if (!customerId) {
1720
+ return cb(new Error('customerId is required'), null);
1721
+ }
1722
+ if (!startDate) {
1723
+ return cb(new Error('startDate is required'), null);
1724
+ }
1725
+ if (!endDate) {
1726
+ return cb(new Error('endDate is required'), null);
1727
+ }
1728
+
1729
+ let query = self
1730
+ .find({
1731
+ '_id': { $in: orgIds },
1732
+ 'valuations': {
1733
+ $elemMatch: {
1734
+ 'date': { $gte: startDate, $lte: endDate },
1735
+ 'customer': customerId
1736
+ }
1737
+ }
1738
+ })
1739
+ .select('_id valuations');
1740
+
1741
+ query.exec(function(err, orgs) {
1742
+
1743
+ if (err) { return cb(err, null); }
1744
+
1745
+ return cb(null, orgs);
1746
+
1747
+ });
1748
+
1749
+ };
1750
+
1706
1751
  Organization.statics.getFlags = function getFlags(orgid, options, cb) {
1707
1752
 
1708
1753
  const self = this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "11.18.0",
3
+ "version": "11.20.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",