@dhyasama/totem-models 12.3.0 → 12.4.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.
@@ -39,9 +39,7 @@ module.exports = function(mongoose, config) {
39
39
 
40
40
  });
41
41
 
42
- LimitedPartnerCampaign.statics.getById = function getById(campaignId, customerId, options, cb) {
43
-
44
- const self = this;
42
+ LimitedPartnerCampaign.statics.getById = async function getById(campaignId, customerId, options, cb) {
45
43
 
46
44
  if (!cb) { throw new Error('cb is required'); }
47
45
  if (!campaignId) { return cb(new Error('campaignId is required'), null); }
@@ -49,19 +47,21 @@ module.exports = function(mongoose, config) {
49
47
  if (!customerId) { return cb(new Error('customerId is required'), null); }
50
48
  if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
51
49
 
52
- const query = self.findOne({
53
- _id: campaignId,
54
- customer: customerId
55
- });
50
+ try {
51
+ const query = this.findOne({
52
+ _id: campaignId,
53
+ customer: customerId
54
+ });
56
55
 
57
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
56
+ const result = await query;
57
+ return cb(null, result);
58
+ } catch(err) { return cb(err); }
58
59
 
59
60
  };
60
61
 
61
62
  // Scheduled but not sent and not done trying
62
- LimitedPartnerCampaign.statics.getUpcoming = function getUpcoming(customerId, options, cb) {
63
+ LimitedPartnerCampaign.statics.getUpcoming = async function getUpcoming(customerId, options, cb) {
63
64
 
64
- const self = this;
65
65
  const now = new Date();
66
66
 
67
67
  if (!cb) { throw new Error('cb is required'); }
@@ -70,64 +70,68 @@ module.exports = function(mongoose, config) {
70
70
 
71
71
  // No need to check send on. If no sentEmailsToQueue then safe to assume sendOn is in the future.
72
72
 
73
- const query = self.find({
74
- customer: customerId,
75
- processed: false,
76
- numberOfFailedAttempts: { $lt: MAX_PROCESSING_ATTEMPTS }
77
- });
73
+ try {
74
+ const query = this.find({
75
+ customer: customerId,
76
+ processed: false,
77
+ numberOfFailedAttempts: { $lt: MAX_PROCESSING_ATTEMPTS }
78
+ });
78
79
 
79
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
80
+ const result = await query;
81
+ return cb(null, result);
82
+ } catch(err) { return cb(err); }
80
83
 
81
84
  };
82
85
 
83
86
  // Scheduled and ready to be sent
84
87
  // Note this doesn't use customer id because it's for the worker and we want all customers.
85
- LimitedPartnerCampaign.statics.getOutbound = function getOutbound(options, cb) {
88
+ LimitedPartnerCampaign.statics.getOutbound = async function getOutbound(options, cb) {
86
89
 
87
- const self = this;
88
90
  const now = new Date();
89
91
 
90
92
  if (!cb) { throw new Error('cb is required'); }
91
93
 
92
- let query = self.find({
93
- processed: false,
94
- numberOfFailedAttempts: { $lt: MAX_PROCESSING_ATTEMPTS },
95
- sendOn: { $lte: now }
96
- });
94
+ try {
95
+ let query = this.find({
96
+ processed: false,
97
+ numberOfFailedAttempts: { $lt: MAX_PROCESSING_ATTEMPTS },
98
+ sendOn: { $lte: now }
99
+ });
97
100
 
98
- query.populate('customer', 'name logoUrl customer');
101
+ query.populate('customer', 'name logoUrl customer');
99
102
 
100
- // Earliest first
101
- query.sort({ sendOn: 1 });
103
+ // Earliest first
104
+ query.sort({ sendOn: 1 });
102
105
 
103
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
106
+ const result = await query;
107
+ return cb(null, result);
108
+ } catch(err) { return cb(err); }
104
109
 
105
110
  };
106
111
 
107
112
  // Scheduled and sent or done trying
108
- LimitedPartnerCampaign.statics.getHistorical = function getHistorical(customerId, options, cb) {
109
-
110
- const self = this;
113
+ LimitedPartnerCampaign.statics.getHistorical = async function getHistorical(customerId, options, cb) {
111
114
 
112
115
  if (!cb) { throw new Error('cb is required'); }
113
116
  if (!customerId) { return cb(new Error('customerId is required'), null); }
114
117
  if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
115
118
 
116
- const query = self.find({
117
- customer: customerId,
118
- $or: [
119
- { processed: true },
120
- { numberOfFailedAttempts: { $gt: MAX_PROCESSING_ATTEMPTS } }
121
- ]
122
- });
119
+ try {
120
+ const query = this.find({
121
+ customer: customerId,
122
+ $or: [
123
+ { processed: true },
124
+ { numberOfFailedAttempts: { $gt: MAX_PROCESSING_ATTEMPTS } }
125
+ ]
126
+ });
123
127
 
124
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
128
+ const result = await query;
129
+ return cb(null, result);
130
+ } catch(err) { return cb(err); }
125
131
 
126
132
  };
127
133
 
128
- LimitedPartnerCampaign.statics.remove = function remove(campaignId, customerId, options, cb) {
129
-
130
- const self = this;
134
+ LimitedPartnerCampaign.statics.remove = async function remove(campaignId, customerId, options, cb) {
131
135
 
132
136
  if (!cb) { throw new Error('cb is required'); }
133
137
  if (!campaignId) { return cb(new Error('campaignId is required'), null); }
@@ -135,22 +139,28 @@ module.exports = function(mongoose, config) {
135
139
  if (!customerId) { return cb(new Error('customerId is required'), null); }
136
140
  if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
137
141
 
138
- const query = self.findOneAndDelete({
139
- _id: campaignId,
140
- customer: customerId
141
- });
142
+ try {
143
+ const query = this.findOneAndDelete({
144
+ _id: campaignId,
145
+ customer: customerId
146
+ });
142
147
 
143
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
148
+ const result = await query;
149
+ return cb(null, result);
150
+ } catch(err) { return cb(err); }
144
151
 
145
152
  // remove associated limited partner communications at the business logic layer
146
153
 
147
154
  };
148
155
 
149
- LimitedPartnerCampaign.statics.upsert = function upsert(doc, options, cb) {
156
+ LimitedPartnerCampaign.statics.upsert = async function upsert(doc, options, cb) {
150
157
 
151
158
  if (!doc) { return cb(new Error('doc is required'), null); }
152
159
 
153
- doc.save().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
160
+ try {
161
+ const result = await doc.save();
162
+ return cb(null, result);
163
+ } catch(err) { return cb(err); }
154
164
 
155
165
  };
156
166
 
@@ -165,4 +175,4 @@ module.exports = function(mongoose, config) {
165
175
 
166
176
  mongoose.model('LimitedPartnerCampaign', LimitedPartnerCampaign);
167
177
 
168
- };
178
+ };
@@ -48,42 +48,42 @@ module.exports = function(mongoose, config) {
48
48
 
49
49
  });
50
50
 
51
- LimitedPartnerCommunication.statics.getByCampaign = function getByCampaign(campaignId, options, cb) {
52
-
53
- const self = this;
51
+ LimitedPartnerCommunication.statics.getByCampaign = async function getByCampaign(campaignId, options, cb) {
54
52
 
55
53
  if (!cb) { throw new Error('cb is required'); }
56
54
  if (!campaignId) { return cb(new Error('campaignId is required'), null); }
57
55
  if (!mongoose.Types.ObjectId.isValid(campaignId)) { return cb(new Error('campaignId is not a valid ObjectId'), null); }
58
56
 
59
- let query = self.find({
60
- campaign: campaignId
61
- });
57
+ try {
58
+ let query = this.find({
59
+ campaign: campaignId
60
+ });
62
61
 
63
- query.populate('limitedPartner', 'name');
62
+ query.populate('limitedPartner', 'name');
64
63
 
65
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
64
+ const result = await query;
65
+ return cb(null, result);
66
+ } catch(err) { return cb(err); }
66
67
 
67
68
  };
68
69
 
69
- LimitedPartnerCommunication.statics.getByCampaigns = function getByCampaigns(campaignIds, options, cb) {
70
-
71
- const self = this;
70
+ LimitedPartnerCommunication.statics.getByCampaigns = async function getByCampaigns(campaignIds, options, cb) {
72
71
 
73
72
  if (!cb) { throw new Error('cb is required'); }
74
73
 
75
- const query = self.find({
76
- campaign: { $in: campaignIds }
77
- });
74
+ try {
75
+ const query = this.find({
76
+ campaign: { $in: campaignIds }
77
+ });
78
78
 
79
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
79
+ const result = await query;
80
+ return cb(null, result);
81
+ } catch(err) { return cb(err); }
80
82
 
81
83
  };
82
84
 
83
85
  // So we can put these on person pages
84
- LimitedPartnerCommunication.statics.getByEmail = function getByEmail(email, options, cb) {
85
-
86
- const self = this;
86
+ LimitedPartnerCommunication.statics.getByEmail = async function getByEmail(email, options, cb) {
87
87
 
88
88
  if (!cb) { throw new Error('cb is required'); }
89
89
  if (!email) { return cb(new Error('email is required'), null); }
@@ -91,35 +91,37 @@ module.exports = function(mongoose, config) {
91
91
  if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
92
92
  if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
93
93
 
94
- let query = self.find({
95
- email: email,
96
- customer: options.CUSTOMER_ID
97
- });
94
+ try {
95
+ let query = this.find({
96
+ email: email,
97
+ customer: options.CUSTOMER_ID
98
+ });
98
99
 
99
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
100
+ const result = await query;
101
+ return cb(null, result);
102
+ } catch(err) { return cb(err); }
100
103
 
101
104
  };
102
105
 
103
- LimitedPartnerCommunication.statics.getById = function getById(id, options, cb) {
104
-
105
- const self = this;
106
+ LimitedPartnerCommunication.statics.getById = async function getById(id, options, cb) {
106
107
 
107
108
  if (!cb) { throw new Error('cb is required'); }
108
109
  if (!id) { return cb(new Error('id is required'), null); }
109
110
  if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
110
111
 
111
- let query = self.find({
112
- _id: id
113
- });
112
+ try {
113
+ let query = this.find({
114
+ _id: id
115
+ });
114
116
 
115
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
117
+ const result = await query;
118
+ return cb(null, result);
119
+ } catch(err) { return cb(err); }
116
120
 
117
121
  };
118
122
 
119
123
  // So we can put these on lp pages
120
- LimitedPartnerCommunication.statics.getForLimitedPartner = function getForLimitedPartner(lpid, options, cb) {
121
-
122
- const self = this;
124
+ LimitedPartnerCommunication.statics.getForLimitedPartner = async function getForLimitedPartner(lpid, options, cb) {
123
125
 
124
126
  if (!cb) { throw new Error('cb is required'); }
125
127
  if (!lpid) { return cb(new Error('lpid is required'), null); }
@@ -128,106 +130,118 @@ module.exports = function(mongoose, config) {
128
130
  if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
129
131
  if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
130
132
 
131
- let query = self.find({
132
- limitedPartner: lpid,
133
- customer: options.CUSTOMER_ID
134
- });
133
+ try {
134
+ let query = this.find({
135
+ limitedPartner: lpid,
136
+ customer: options.CUSTOMER_ID
137
+ });
135
138
 
136
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
139
+ const result = await query;
140
+ return cb(null, result);
141
+ } catch(err) { return cb(err); }
137
142
 
138
143
  };
139
144
 
140
- LimitedPartnerCommunication.statics.getByPostmarkMessageId = function getByPostmarkMessageId(postmarkMessageId, cb) {
141
-
142
- const self = this;
145
+ LimitedPartnerCommunication.statics.getByPostmarkMessageId = async function getByPostmarkMessageId(postmarkMessageId, cb) {
143
146
 
144
- const query = self.findOne({ postmarkMessageId: postmarkMessageId });
147
+ try {
148
+ const query = this.findOne({ postmarkMessageId: postmarkMessageId });
145
149
 
146
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
150
+ const result = await query;
151
+ return cb(null, result);
152
+ } catch(err) { return cb(err); }
147
153
 
148
154
  };
149
155
 
150
- LimitedPartnerCommunication.statics.getUnsentByCampaigns = function getUnsentByCampaigns(campaignIds, options, cb) {
151
-
152
- const self = this;
156
+ LimitedPartnerCommunication.statics.getUnsentByCampaigns = async function getUnsentByCampaigns(campaignIds, options, cb) {
153
157
 
154
158
  if (!cb) { throw new Error('cb is required'); }
155
159
 
156
- const query = self.find({
157
- campaign: { $in: campaignIds },
158
- $and: [{ sentOn: null }] // matches null or not set
159
- });
160
+ try {
161
+ const query = this.find({
162
+ campaign: { $in: campaignIds },
163
+ $and: [{ sentOn: null }] // matches null or not set
164
+ });
160
165
 
161
- query.populate('limitedPartner', 'name');
166
+ query.populate('limitedPartner', 'name');
162
167
 
163
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
168
+ const result = await query;
169
+ return cb(null, result);
170
+ } catch(err) { return cb(err); }
164
171
 
165
172
  };
166
173
 
167
- LimitedPartnerCommunication.statics.modifyById = function modifyById(id, update, options, cb) {
168
-
169
- const self = this;
174
+ LimitedPartnerCommunication.statics.modifyById = async function modifyById(id, update, options, cb) {
170
175
 
171
176
  if (!cb) throw new Error('cb is required');
172
177
  if (!id) { return cb(new Error('id is required'), null); }
173
178
  if (!update) { return cb(new Error('update is required'), null); }
174
179
 
175
- self.findByIdAndUpdate(id, update, { upsert: false, new: true }).then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
180
+ try {
181
+ const result = await this.findByIdAndUpdate(id, update, { upsert: false, new: true });
182
+ return cb(null, result);
183
+ } catch(err) { return cb(err); }
176
184
 
177
185
  };
178
186
 
179
- LimitedPartnerCommunication.statics.modifyOne = function modifyOne(conditions, update, options, cb) {
180
-
181
- const self = this;
187
+ LimitedPartnerCommunication.statics.modifyOne = async function modifyOne(conditions, update, options, cb) {
182
188
 
183
189
  if (!cb) throw new Error('cb is required');
184
190
  if (!conditions) { return cb(new Error('conditions is required'), null); }
185
191
  if (!update) { return cb(new Error('update is required'), null); }
186
192
 
187
- const query = self.findOneAndUpdate(conditions, update, { upsert: false, new: true });
193
+ try {
194
+ const query = this.findOneAndUpdate(conditions, update, { upsert: false, new: true });
188
195
 
189
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
196
+ const result = await query;
197
+ return cb(null, result);
198
+ } catch(err) { return cb(err); }
190
199
 
191
200
  };
192
201
 
193
202
  // Remove all the docs associated with a campaign
194
- LimitedPartnerCommunication.statics.removeByCampaign = function removeByCampaign(campaignId, options, cb) {
195
-
196
- const self = this;
203
+ LimitedPartnerCommunication.statics.removeByCampaign = async function removeByCampaign(campaignId, options, cb) {
197
204
 
198
205
  if (!cb) { throw new Error('cb is required'); }
199
206
  if (!campaignId) { return cb(new Error('campaignId is required'), null); }
200
207
  if (!mongoose.Types.ObjectId.isValid(campaignId)) { return cb(new Error('campaignId is not a valid ObjectId'), null); }
201
208
 
202
- const query = self.deleteMany({
203
- campaign: campaignId
204
- });
209
+ try {
210
+ const query = this.deleteMany({
211
+ campaign: campaignId
212
+ });
205
213
 
206
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
214
+ const result = await query;
215
+ return cb(null, result);
216
+ } catch(err) { return cb(err); }
207
217
 
208
218
  };
209
219
 
210
- LimitedPartnerCommunication.statics.removeById = function removeById(id, options, cb) {
211
-
212
- const self = this;
220
+ LimitedPartnerCommunication.statics.removeById = async function removeById(id, options, cb) {
213
221
 
214
222
  if (!cb) { throw new Error('cb is required'); }
215
223
  if (!id) { return cb(new Error('id is required'), null); }
216
224
  if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
217
225
 
218
- const query = self.findByIdAndDelete({
219
- _id: id
220
- });
226
+ try {
227
+ const query = this.findByIdAndDelete({
228
+ _id: id
229
+ });
221
230
 
222
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
231
+ const result = await query;
232
+ return cb(null, result);
233
+ } catch(err) { return cb(err); }
223
234
 
224
235
  };
225
236
 
226
- LimitedPartnerCommunication.statics.upsert = function upsert(doc, options, cb) {
237
+ LimitedPartnerCommunication.statics.upsert = async function upsert(doc, options, cb) {
227
238
 
228
239
  if (!doc) { return cb(new Error('doc is required'), null); }
229
240
 
230
- doc.save().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
241
+ try {
242
+ const result = await doc.save();
243
+ return cb(null, result);
244
+ } catch(err) { return cb(err); }
231
245
 
232
246
  };
233
247
 
@@ -5,8 +5,7 @@ module.exports = function(mongoose, config) {
5
5
  let
6
6
 
7
7
  Schema = mongoose.Schema,
8
- _ = require('underscore'),
9
- async = require('async');
8
+ _ = require('underscore');
10
9
 
11
10
  const LimitedPartnerContactGroup = new Schema({
12
11
 
@@ -30,9 +29,7 @@ module.exports = function(mongoose, config) {
30
29
  });
31
30
 
32
31
  // Get a contact group
33
- LimitedPartnerContactGroup.statics.getById = function (id, options, cb) {
34
-
35
- const self = this;
32
+ LimitedPartnerContactGroup.statics.getById = async function (id, options, cb) {
36
33
 
37
34
  if (!cb) { throw new Error('cb is required'); }
38
35
  if (!id) { return cb(new Error('id is required'), null); }
@@ -41,57 +38,58 @@ module.exports = function(mongoose, config) {
41
38
  if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
42
39
  if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
43
40
 
44
- let query = self.findOne({
45
- '_id': id,
46
- 'customer': options.CUSTOMER_ID
47
- });
41
+ try {
42
+ let query = this.findOne({
43
+ '_id': id,
44
+ 'customer': options.CUSTOMER_ID
45
+ });
48
46
 
49
- query.populate('contacts.limitedPartner', 'name');
47
+ query.populate('contacts.limitedPartner', 'name');
50
48
 
51
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
49
+ const result = await query;
50
+ return cb(null, result);
51
+ } catch(err) { return cb(err); }
52
52
 
53
53
  };
54
54
 
55
55
  // Get all contact groups for a customer
56
- LimitedPartnerContactGroup.statics.getForCustomer = function (customerId, options, cb) {
57
-
58
- const self = this;
56
+ LimitedPartnerContactGroup.statics.getForCustomer = async function (customerId, options, cb) {
59
57
 
60
58
  if (!cb) { throw new Error('cb is required'); }
61
59
  if (!customerId) { return cb(new Error('customerId is required'), null); }
62
60
  if (!mongoose.Types.ObjectId.isValid(customerId)) { return cb(new Error('customerId is not a valid ObjectId'), null); }
63
61
 
64
- let query = self.find({
65
- 'customer': customerId
66
- });
62
+ try {
63
+ let query = this.find({
64
+ 'customer': customerId
65
+ });
67
66
 
68
- query.populate('contacts.limitedPartner', 'name');
67
+ query.populate('contacts.limitedPartner', 'name');
69
68
 
70
- query.exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
69
+ const result = await query;
70
+ return cb(null, result);
71
+ } catch(err) { return cb(err); }
71
72
 
72
73
  };
73
74
 
74
- LimitedPartnerContactGroup.statics.removeForCustomer = function removeForCustomer(customerId, cb) {
75
-
76
- let self = this;
77
-
78
- self
79
- .find({ customer: customerId })
80
- .exec().then(function(groups) {async.each(groups, function(group, callback) {
81
- group.deleteOne().then(function() { callback(null, group); }).catch(function(err) { callback(err); });
82
- }, function(err) {
83
- return cb(err, null);
84
- });
75
+ LimitedPartnerContactGroup.statics.removeForCustomer = async function removeForCustomer(customerId, cb) {
85
76
 
86
- }).catch(function(err) { cb(err); });
77
+ try {
78
+ const groups = await this.find({ customer: customerId });
79
+ await Promise.all(groups.map(function(group) { return group.deleteOne(); }));
80
+ return cb(null, null);
81
+ } catch(err) { return cb(err); }
87
82
 
88
83
  };
89
84
 
90
- LimitedPartnerContactGroup.statics.upsert = function upsert(doc, options, cb) {
85
+ LimitedPartnerContactGroup.statics.upsert = async function upsert(doc, options, cb) {
91
86
 
92
87
  if (!doc) { return cb(new Error('doc is required'), null); }
93
88
 
94
- doc.save().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
89
+ try {
90
+ const result = await doc.save();
91
+ return cb(null, result);
92
+ } catch(err) { return cb(err); }
95
93
 
96
94
  };
97
95
 
@@ -51,29 +51,33 @@ module.exports = function(mongoose, config) {
51
51
 
52
52
  });
53
53
 
54
- LimitedPartnerReportGenerator.statics.getById = function (id, options, cb) {
55
-
56
- const self = this;
54
+ LimitedPartnerReportGenerator.statics.getById = async function (id, options, cb) {
57
55
 
58
56
  if (!cb) { throw new Error('cb is required'); }
59
57
  if (!id) { return cb(new Error('id is required'), null); }
60
58
  if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
61
59
 
62
- self.findOne({
63
- '_id': id
64
- }).exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
60
+ try {
61
+ const result = await this.findOne({
62
+ '_id': id
63
+ });
64
+ return cb(null, result);
65
+ } catch(err) { return cb(err); }
65
66
 
66
67
  };
67
68
 
68
- LimitedPartnerReportGenerator.statics.upsert = function upsert(doc, options, cb) {
69
+ LimitedPartnerReportGenerator.statics.upsert = async function upsert(doc, options, cb) {
69
70
 
70
71
  if (!doc) { return cb(new Error('doc is required'), null); }
71
72
 
72
- doc.save().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
73
+ try {
74
+ const result = await doc.save();
75
+ return cb(null, result);
76
+ } catch(err) { return cb(err); }
73
77
 
74
78
  };
75
79
  LimitedPartnerReportGenerator.set('autoIndex', false);
76
80
 
77
81
  mongoose.model('LimitedPartnerReportGenerator', LimitedPartnerReportGenerator);
78
82
 
79
- };
83
+ };