@dhyasama/totem-models 5.0.0 → 5.0.2

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/Deal.js CHANGED
@@ -123,15 +123,18 @@ module.exports = function(mongoose, config) {
123
123
 
124
124
  var self = this;
125
125
 
126
+ console.log('Deal.statics.getForCustomer');
127
+ console.log('customerId', customerId);
128
+
126
129
  self
127
130
  .find({ 'customer': customerId })
128
- .populate('organization', 'name logoUrl website websiteAliases')
129
- .populate('messages')
130
- .populate('sources.person', 'name avatarUrl')
131
- .populate({
132
- path: 'documents',
133
- match: { customer: customerId }
134
- })
131
+ // .populate('organization', 'name logoUrl website websiteAliases')
132
+ // .populate('messages')
133
+ // .populate('sources.person', 'name avatarUrl')
134
+ // .populate({
135
+ // path: 'documents',
136
+ // match: { customer: customerId }
137
+ // })
135
138
  .exec(cb);
136
139
 
137
140
  };
@@ -570,45 +570,23 @@ module.exports = function(mongoose, config) {
570
570
  // Note that running a method on a document does not save it
571
571
  ///////////////////////////////////////////////////////////////////////////////////////
572
572
 
573
- Organization.methods.addDeal = function(status, customer, account) {
573
+ Organization.methods.addDeal = function(deal) {
574
574
 
575
575
  var self = this;
576
576
 
577
577
  // Validate inputs
578
- if (!customer) throw new Error('Customer is required');
579
- if (!status) throw new Error('Status is required');
580
- if (!account) throw new Error('Account is required');
581
-
582
- // Check if status exists and is active
583
- var statusMatch = _.find(customer.customer.deals.statuses, function(s) { return s.name.toLowerCase() == status.toLowerCase() && s.active; });
584
- if (!statusMatch) throw new Error('This deal status is not valid for this customer');
585
-
586
- // Prepare an entry to track history of deal
587
- var historyEntry = {
588
- timestamp: new Date(),
589
- account: account,
590
- status: status
591
- };
578
+ if (!deal) throw new Error('deal is required');
592
579
 
593
580
  // Check if this deal already exists
594
581
  var dealMatch = _.find(self.deals, function(d) {
595
- return utils.getIdAsString(d, 'customer') == customer._id.toString();
582
+ return d._id.toString() === deal._id.toString();
596
583
  });
597
584
 
598
585
  // Update the deal
599
- if (dealMatch) {
600
- dealMatch.status = status;
601
- dealMatch.history.push(historyEntry);
602
- }
586
+ if (dealMatch) { dealMatch = deal; }
603
587
 
604
588
  // Add the deal
605
- else {
606
- self.deals.push({
607
- customer: customer,
608
- status: status,
609
- history: [historyEntry]
610
- });
611
- }
589
+ else { self.deals.push(deal); }
612
590
 
613
591
  };
614
592
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",