@dhyasama/totem-models 4.5.2 → 4.5.4
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/Organization.js +7 -15
- package/package.json +1 -1
- package/test/Organization.js +580 -550
package/lib/Organization.js
CHANGED
|
@@ -384,19 +384,15 @@ module.exports = function(mongoose, config) {
|
|
|
384
384
|
Organization.virtual('customer.deals.activeStatuses').get(function () {
|
|
385
385
|
|
|
386
386
|
var self = this;
|
|
387
|
-
var statuses = [];
|
|
388
|
-
|
|
389
|
-
// Don't return statuses for a different customer
|
|
390
|
-
if (self._id.toString() != config.CUSTOMER_ID) return statuses;
|
|
391
387
|
|
|
392
388
|
// Backwards schema compatibility
|
|
393
|
-
|
|
389
|
+
if (!self.customer.deals) return [];
|
|
394
390
|
|
|
395
391
|
// Deals aren't on for customer
|
|
396
|
-
else if (!self.customer.deals.active) return
|
|
392
|
+
else if (!self.customer.deals.active) return [];
|
|
397
393
|
|
|
398
394
|
// Get active status names and sort them
|
|
399
|
-
statuses = _.filter(self.customer.deals.statuses, function(s) { return s.active; });
|
|
395
|
+
var statuses = _.filter(self.customer.deals.statuses, function(s) { return s.active; });
|
|
400
396
|
statuses = _.sortBy(statuses, 'order');
|
|
401
397
|
statuses = _.pluck(statuses, 'name');
|
|
402
398
|
|
|
@@ -594,27 +590,22 @@ module.exports = function(mongoose, config) {
|
|
|
594
590
|
|
|
595
591
|
// Check if this deal already exists
|
|
596
592
|
var dealMatch = _.find(self.deals, function(d) {
|
|
597
|
-
|
|
598
|
-
return cid == customer._id.toString();
|
|
593
|
+
return utils.getIdAsString(d, 'customer') == customer._id.toString();
|
|
599
594
|
});
|
|
600
595
|
|
|
601
596
|
// Update the deal
|
|
602
597
|
if (dealMatch) {
|
|
603
|
-
|
|
604
598
|
dealMatch.status = status;
|
|
605
599
|
dealMatch.history.push(historyEntry);
|
|
606
|
-
|
|
607
600
|
}
|
|
608
601
|
|
|
609
602
|
// Add the deal
|
|
610
603
|
else {
|
|
611
|
-
|
|
612
604
|
self.deals.push({
|
|
613
605
|
customer: customer,
|
|
614
606
|
status: status,
|
|
615
607
|
history: [historyEntry]
|
|
616
608
|
});
|
|
617
|
-
|
|
618
609
|
}
|
|
619
610
|
|
|
620
611
|
};
|
|
@@ -1050,17 +1041,18 @@ module.exports = function(mongoose, config) {
|
|
|
1050
1041
|
|
|
1051
1042
|
};
|
|
1052
1043
|
|
|
1053
|
-
Organization.statics.getDeals = function getDeals(cb) {
|
|
1044
|
+
Organization.statics.getDeals = function getDeals(customerId, cb) {
|
|
1054
1045
|
|
|
1055
1046
|
var self = this;
|
|
1056
1047
|
|
|
1057
1048
|
self
|
|
1058
|
-
.find({ 'deals.customer':
|
|
1049
|
+
.find({ 'deals.customer': customerId, 'deleted': { $ne: true } })
|
|
1059
1050
|
.select('name website websiteAliases deals')
|
|
1060
1051
|
.exec(function(err, result) {
|
|
1061
1052
|
|
|
1062
1053
|
if (err) return cb(err, null);
|
|
1063
1054
|
|
|
1055
|
+
result.deals = _.reject(result.deals, function(item) { return !item.customer || item.customer.toString() != customerId.toString(); });
|
|
1064
1056
|
result = _.map(result, function(item) {
|
|
1065
1057
|
return {
|
|
1066
1058
|
name: item.name,
|