@dhyasama/totem-models 11.42.0 → 11.43.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/Account.js CHANGED
@@ -93,7 +93,7 @@ module.exports = function(mongoose, config) {
93
93
  return self.totemLive && self.totemLive.sheetsUser;
94
94
  });
95
95
 
96
- Account.statics.findOneByEmail = function(email, options, cb) {
96
+ Account.statics.findByEmail = function(email, options, cb) {
97
97
 
98
98
  let self = this;
99
99
 
@@ -104,50 +104,40 @@ module.exports = function(mongoose, config) {
104
104
 
105
105
  let query = { email: email.toLowerCase() };
106
106
 
107
- if (options.current !== undefined) {
108
- query.current = options.current;
109
- }
107
+ if (options.current || options.customerId) {
110
108
 
111
- if (options.customerId !== undefined) {
112
- query.org = options.current;
113
- }
114
-
115
- self
116
- .findOne(query)
117
- .populate('person')
118
- .exec(function(err, account) {
119
-
120
- if (err) { return cb(err); }
121
- else if (!account) { return cb(null, null); }
109
+ if (options.current !== undefined) query.current = options.current;
110
+ if (options.customerId !== undefined) query.org = options.current;
111
+
112
+ self
113
+ .findOne(query)
114
+ .populate('person')
115
+ .exec(function(err, account) {
122
116
 
123
- if (account.populated('person')) {
117
+ if (err) { return cb(err); }
118
+ else if (!account) { return cb(null, null); }
124
119
 
125
- if (account.org) { helpers.cleanPerson(account.person, account.org); }
126
- else { account.person.sources = []; }
127
-
128
- }
129
-
130
- return cb(null, account);
120
+ if (account.populated('person')) {
131
121
 
132
- });
122
+ if (account.org) { helpers.cleanPerson(account.person, account.org); }
123
+ else { account.person.sources = []; }
133
124
 
134
- };
125
+ }
135
126
 
136
- Account.statics.findAllByEmail = function(email, options, cb) {
127
+ return cb(null, account);
137
128
 
138
- let self = this;
129
+ });
139
130
 
140
- if (!cb) { throw new Error('cb is required'); }
141
- if (!email) { return cb(new Error('email is required'), null); }
131
+ }
142
132
 
143
- options = helpers.getDefaultOptions(options);
133
+ else {
144
134
 
145
- let query = { email: email.toLowerCase() };
135
+ self
136
+ .find(query)
137
+ .populate('org name')
138
+ .exec(cb);
146
139
 
147
- self
148
- .find(query)
149
- .populate('org name')
150
- .exec(cb);
140
+ }
151
141
 
152
142
  };
153
143
 
@@ -413,4 +403,4 @@ module.exports = function(mongoose, config) {
413
403
 
414
404
  mongoose.model('Account', Account);
415
405
 
416
- };
406
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "11.42.0",
3
+ "version": "11.43.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
package/test/Account.js CHANGED
@@ -117,7 +117,7 @@ describe('Account', function() {
117
117
 
118
118
  it('finds by email', function(done) {
119
119
 
120
- Account.findByEmail('test@totemvc.com', function(err, account) {
120
+ Account.findByEmail('test@totemvc.com', { current: true }, function(err, account) {
121
121
  should.not.exist(err);
122
122
  should.exist(account);
123
123
  done();
@@ -127,7 +127,7 @@ describe('Account', function() {
127
127
 
128
128
  it('finds by uppercase email', function(done) {
129
129
 
130
- Account.findByEmail('TEST@TOTEMVC.COM', function(err, account) {
130
+ Account.findByEmail('TEST@TOTEMVC.COM', { current: true }, function(err, account) {
131
131
  should.not.exist(err);
132
132
  should.exist(account);
133
133
  done();