@dhyasama/totem-models 11.51.0 → 11.53.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/LimitedPartner.js +37 -2
- package/lib/Organization.js +13 -0
- package/package.json +1 -1
package/lib/LimitedPartner.js
CHANGED
|
@@ -494,9 +494,12 @@ module.exports = function(mongoose, config) {
|
|
|
494
494
|
if (!personId) { return cb(new Error('personId is required'), null); }
|
|
495
495
|
if (!mongoose.Types.ObjectId.isValid(personId)) { return cb(new Error('personId is not a valid ObjectId'), null); }
|
|
496
496
|
if (!options) { return cb(new Error('options is required'), null); }
|
|
497
|
-
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
498
|
-
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
499
497
|
|
|
498
|
+
if (!options.isWorkerProcess) {
|
|
499
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
500
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
501
|
+
}
|
|
502
|
+
|
|
500
503
|
options = helpers.getDefaultOptions(options);
|
|
501
504
|
|
|
502
505
|
let query;
|
|
@@ -519,6 +522,38 @@ module.exports = function(mongoose, config) {
|
|
|
519
522
|
|
|
520
523
|
};
|
|
521
524
|
|
|
525
|
+
LimitedPartner.statics.getByPersonIds = function(personIds, options, cb) {
|
|
526
|
+
|
|
527
|
+
const self = this;
|
|
528
|
+
|
|
529
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
530
|
+
if (!personIds) { return cb(new Error('personIds is required'), null); }
|
|
531
|
+
if (!options) { return cb(new Error('options is required'), null); }
|
|
532
|
+
|
|
533
|
+
if (!options.isWorkerProcess) {
|
|
534
|
+
if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
|
|
535
|
+
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
options = helpers.getDefaultOptions(options);
|
|
539
|
+
|
|
540
|
+
let query;
|
|
541
|
+
|
|
542
|
+
if (options.isWorkerProcess) {
|
|
543
|
+
query = self.find({'people': { $in : personIds }}, getReadFilterKeys(options.role));
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
query = self.find({'people': { $in : personIds }, customer: options.CUSTOMER_ID }, getReadFilterKeys(options.role));
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
query.exec(function (err, lps) {
|
|
550
|
+
if (err) { return cb(err, null); }
|
|
551
|
+
lps = _.sortBy(lps, function(lp) { return lp.name ? lp.name.toLowerCase() : ''; });
|
|
552
|
+
return cb(null, lps);
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
};
|
|
556
|
+
|
|
522
557
|
LimitedPartner.statics.getFlags = function getFlags(lpid, options, cb) {
|
|
523
558
|
|
|
524
559
|
const self = this;
|
package/lib/Organization.js
CHANGED
|
@@ -1282,6 +1282,19 @@ module.exports = function(mongoose, config) {
|
|
|
1282
1282
|
|
|
1283
1283
|
};
|
|
1284
1284
|
|
|
1285
|
+
Organization.statics.getByPersonIds = function getByPersonIds(personIds, cb) {
|
|
1286
|
+
|
|
1287
|
+
const self = this;
|
|
1288
|
+
|
|
1289
|
+
if (!cb) { throw new Error('cb is required'); }
|
|
1290
|
+
if (!personIds) { return cb(new Error('personIds is required'), null); }
|
|
1291
|
+
|
|
1292
|
+
self
|
|
1293
|
+
.find({'people.person': { $in : personIds } })
|
|
1294
|
+
.exec(cb);
|
|
1295
|
+
|
|
1296
|
+
};
|
|
1297
|
+
|
|
1285
1298
|
Organization.statics.findBySlug = function findBySlug(slug, cb) {
|
|
1286
1299
|
this.findOne({ slug: slug, 'deleted': {$ne: true} }).exec(cb);
|
|
1287
1300
|
};
|