@dhyasama/totem-models 6.15.4 → 6.16.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.
@@ -429,6 +429,27 @@ module.exports = function(mongoose, config) {
429
429
 
430
430
  };
431
431
 
432
+ LimitedPartner.statics.getByName = function(lpName, role, cb) {
433
+
434
+ var self = this;
435
+ var query;
436
+
437
+ var getLps = function() {
438
+ query.populate('fundsInvested.fund');
439
+ query.exec(cb);
440
+ };
441
+
442
+ if (CUSTOMER_ID == 'GLOBAL_PROCESS') {
443
+ query = self.find({'name': lpName}, this.getReadFilterKeys(role))
444
+ getLps();
445
+ }
446
+ else {
447
+ query = self.find({'name': lpName, 'fundsInvested.fund': { $in : self.customerFunds }}, self.getReadFilterKeys(role));
448
+ getLps();
449
+ }
450
+
451
+ };
452
+
432
453
  LimitedPartner.statics.getFlags = function getFlags(lpid, cb) {
433
454
 
434
455
  var self = this;
@@ -692,6 +713,19 @@ module.exports = function(mongoose, config) {
692
713
  return self.customerFunds;
693
714
  };
694
715
 
716
+ LimitedPartner.statics.removeCustomerCommitments = function removeCustomerCommitments(customerId, cb) {
717
+
718
+ var self = this;
719
+
720
+ var query = self.update(
721
+ { 'customer': customerId },
722
+ { $set: { fundsInvested: [] } },
723
+ { multi : true }
724
+ );
725
+ query.exec(cb);
726
+
727
+ };
728
+
695
729
  LimitedPartner.statics.upsert = function(lp, username, role, cb) {
696
730
 
697
731
  if (!lp) { return cb(new Error('lp is required'), null); }
@@ -1818,18 +1818,20 @@ module.exports = function(mongoose, config) {
1818
1818
  this.collection.stats(cb);
1819
1819
  };
1820
1820
 
1821
- Organization.statics.upsert = function(org, username, cb) {
1821
+ LimitedPartner.statics.upsert = function(lp, username, role, cb) {
1822
1822
 
1823
- if (!org) { return cb(new Error('Organization is required'), null); }
1824
- if (!username) { return cb(new Error('Username is required'), null); }
1823
+ if (!lp) { return cb(new Error('lp is required'), null); }
1824
+ if (!username) { return cb(new Error('username is required'), null); }
1825
1825
 
1826
- org.entered.by = username;
1827
- org.entered.on = new Date();
1826
+ lp.entered.by = username;
1827
+ lp.entered.on = new Date();
1828
1828
 
1829
- // Clean up missing references
1830
- org.people = _.reject(org.people, function(item) { return !item.person; });
1831
-
1832
- org.save(cb);
1829
+ lp.extendWithWriteFilter(lp, role);
1830
+ lp.save(function(err, result) {
1831
+ if (err) return cb(err, null);
1832
+ result.applyReadFilter(role);
1833
+ return cb(null, result);
1834
+ });
1833
1835
 
1834
1836
  };
1835
1837
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "6.15.4",
3
+ "version": "6.16.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",