@dhyasama/totem-models 12.2.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.
package/lib/Rate.js CHANGED
@@ -21,37 +21,44 @@ module.exports = function(mongoose, config) {
21
21
 
22
22
  });
23
23
 
24
- Rate.statics.getByDateAndCurrency = function getByDate(options, cb) {
24
+ Rate.statics.getByDateAndCurrency = async function getByDate(options, cb) {
25
25
 
26
26
  if (!cb) { throw new Error('cb is required'); }
27
27
  if (!options) { return cb(new Error('options is required'), null); }
28
28
 
29
- const self = this;
30
-
31
- self
32
- .find({ $and: [{ date: options.date }, { currency: options.currency }] })
33
- .exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
29
+ try {
30
+ const result = await this.find({ $and: [{ date: options.date }, { currency: options.currency }] });
31
+ return cb(null, result);
32
+ } catch(err) {
33
+ return cb(err);
34
+ }
34
35
 
35
36
  };
36
37
 
37
- Rate.statics.getByDatesAndCurrencies = function getByDatesAndCurrencies(options, cb) {
38
+ Rate.statics.getByDatesAndCurrencies = async function getByDatesAndCurrencies(options, cb) {
38
39
 
39
40
  if (!cb) { throw new Error('cb is required'); }
40
- if (!options) { return cb(new Error('options with valid pairs is required'), null); }
41
-
42
- const self = this;
43
-
44
- self
45
- .find({ $or: options.datesAndCurrencies })
46
- .exec().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
41
+ if (!options) { return cb(new Error('options with valid pairs is required'), null); }
42
+
43
+ try {
44
+ const result = await this.find({ $or: options.datesAndCurrencies });
45
+ return cb(null, result);
46
+ } catch(err) {
47
+ return cb(err);
48
+ }
47
49
  };
48
50
 
49
- Rate.statics.upsert = function (rate, cb) {
50
- rate.save().then(function(result) { cb(null, result); }).catch(function(err) { cb(err); });
51
+ Rate.statics.upsert = async function (rate, cb) {
52
+ try {
53
+ const result = await rate.save();
54
+ return cb(null, result);
55
+ } catch(err) {
56
+ return cb(err);
57
+ }
51
58
  };
52
59
  Rate.set('autoIndex', false);
53
60
  Rate.on('index', function(err) { console.log('error building rate indexes: ' + err); });
54
61
 
55
62
  mongoose.model('Rate', Rate);
56
63
 
57
- };
64
+ };