@dhyasama/totem-models 10.53.0 → 10.55.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/index.js CHANGED
@@ -61,7 +61,6 @@ var bootstrap = function(mongoose, config) {
61
61
  require('./lib/Activity.js')(mongoose, config);
62
62
  require('./lib/CalendarEvent.js')(mongoose, config);
63
63
  require('./lib/CapTable.js')(mongoose, config);
64
- require('./lib/Currency.js')(mongoose, config);
65
64
  require('./lib/Document.js')(mongoose, config);
66
65
  require('./lib/Event.js')(mongoose, config);
67
66
  require('./lib/EventAttendee.js')(mongoose, config);
@@ -76,6 +75,7 @@ var bootstrap = function(mongoose, config) {
76
75
  require('./lib/Message.js')(mongoose, config);
77
76
  require('./lib/MessageRecipient.js')(mongoose, config);
78
77
  require('./lib/News.js')(mongoose, config);
78
+ require('./lib/Rate.js')(mongoose, config);
79
79
  require('./lib/Snapshot.js')(mongoose, config);
80
80
  require('./lib/Sync.js')(mongoose, config);
81
81
  require('./lib/Webhook.js')(mongoose, config);
package/lib/Rate.js ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ module.exports = function(mongoose, config) {
4
+
5
+ let
6
+
7
+ Schema = mongoose.Schema,
8
+ _ = require('underscore'),
9
+
10
+ Rate = new Schema({
11
+
12
+ date: { type: Date, required: true },
13
+
14
+ currency: { type: String, required: true },
15
+
16
+ conversions: [{
17
+ _id: false,
18
+ currency: { type: String },
19
+ rate: { type: Number }
20
+ }]
21
+
22
+ });
23
+
24
+ Rate.statics.getByDateAndCurrency = function getByDate(options, cb) {
25
+
26
+ if (!cb) { throw new Error('cb is required'); }
27
+ if (!options) { return cb(new Error('options is required'), null); }
28
+
29
+ const self = this;
30
+
31
+ self
32
+ .find({ $and: [{ date: options.date }, { currency: options.currency }] })
33
+ .exec(cb);
34
+
35
+ };
36
+
37
+ Rate.statics.getByDatesAndCurrencies = function getByDatesAndCurrencies(options, cb) {
38
+
39
+ 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(cb);
47
+ };
48
+
49
+ Rate.statics.upsert = function (rate, cb) {
50
+ rate.save(cb);
51
+ };
52
+
53
+ Rate.set('usePushEach', true);
54
+ Rate.set('autoIndex', false);
55
+ Rate.set('usePushEach', true);
56
+ Rate.on('index', function(err) { console.log('error building rate indexes: ' + err); });
57
+
58
+ mongoose.model('Rate', Rate);
59
+
60
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "10.53.0",
3
+ "version": "10.55.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
package/lib/Currency.js DELETED
@@ -1,41 +0,0 @@
1
- "use strict";
2
-
3
- module.exports = function(mongoose, config) {
4
-
5
- let
6
-
7
- Schema = mongoose.Schema,
8
- _ = require('underscore'),
9
-
10
- Currency = new Schema({
11
-
12
- date: { type: Date, required: true },
13
-
14
- currency: { type: String, required: true },
15
-
16
- conversions: [{
17
- _id: false,
18
- currency: { type: String },
19
- rate: { type: Number }
20
- }]
21
-
22
- });
23
-
24
- Currency.statics.getByDate = function getByDate(date, cb) {
25
- this
26
- .find({date: date, currency: currency})
27
- .exec(cb);
28
- };
29
-
30
- Currency.statics.upsert = function (currency, cb) {
31
- currency.save(cb);
32
- };
33
-
34
- Currency.set('usePushEach', true);
35
- Currency.set('autoIndex', false);
36
- Currency.set('usePushEach', true);
37
- Currency.on('index', function(err) { console.log('error building currency indexes: ' + err); });
38
-
39
- mongoose.model('Currency', Currency);
40
-
41
- };