@dhyasama/totem-models 11.11.0 → 11.13.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.
@@ -12,13 +12,14 @@ module.exports = function(mongoose, config) {
12
12
  org: {
13
13
  type: Schema.ObjectId,
14
14
  ref: 'Organization',
15
- required: false,
16
- default: null
15
+ required: true
17
16
  },
18
17
 
19
- updatedOn: { type: Date, required: false, default: null },
18
+ updatedOn: { type: Date, required: true },
20
19
 
21
- entity: { type: Schema.Types.Mixed, required: false, default: null },
20
+ entityId: { type: String, required: true, unique: true },
21
+
22
+ entity: { type: Schema.Types.Mixed, required: true },
22
23
 
23
24
  });
24
25
 
@@ -62,7 +63,7 @@ module.exports = function(mongoose, config) {
62
63
  };
63
64
 
64
65
  DiffbotArticle.set('usePushEach', true);
65
- DiffbotArticle.set('autoIndex', false);
66
+ DiffbotArticle.set('autoIndex', true);
66
67
  DiffbotArticle.on('index', function(err) { console.log('error building DiffbotArticle indexes: ' + err); });
67
68
 
68
69
  mongoose.model('DiffbotArticle', DiffbotArticle);
@@ -85,6 +85,38 @@ module.exports = function(mongoose, config) {
85
85
 
86
86
  };
87
87
 
88
+ Interaction.statics.getById = function getById(id, options, cb) {
89
+
90
+ const self = this;
91
+
92
+ if (!cb) { throw new Error('cb is required'); }
93
+ if (!id) { return cb(new Error('id is required'), null); }
94
+ if (!mongoose.Types.ObjectId.isValid(id)) { return cb(new Error('id is not a valid ObjectId'), null); }
95
+ if (!options) { return cb(new Error('options is required'), null); }
96
+
97
+ options = helpers.getDefaultOptions(options);
98
+
99
+ if (!options.isWorkerProcess) {
100
+ if (!options.CUSTOMER_ID) { return cb(new Error('options.CUSTOMER_ID is required'), null); }
101
+ if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
102
+ }
103
+
104
+ let query = self.findById(id);
105
+
106
+ query.populate('attendees.internal');
107
+ query.populate('attendees.external');
108
+
109
+ query.exec(function(err, result) {
110
+
111
+ if (err) { return cb(err, null); }
112
+
113
+ if (options.isWorkerProcess) { return cb(null, result); }
114
+ else { return cb(null, result); }
115
+
116
+ });
117
+
118
+ };
119
+
88
120
  Interaction.statics.getForCustomer = function getForCustomer(customerId, since, cb) {
89
121
 
90
122
  if (!cb) { throw new Error('cb is required'); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "11.11.0",
3
+ "version": "11.13.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",