@dhyasama/totem-models 11.10.0 → 11.12.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/Folder.js CHANGED
@@ -50,23 +50,12 @@ module.exports = function(mongoose, config) {
50
50
 
51
51
  const self = this;
52
52
 
53
- const populateFolders = async (folders) => {
54
- for (const folder of folders) {
55
- const childFolders = await self.find({ parent: folder._id });
56
- folder.children = await populateFolders(childFolders);
57
- }
58
- return folders;
59
- };
60
-
61
53
  self.find({
62
54
  'entity.id': entity.id,
63
55
  'entity.model': entity.model,
64
- customer: options.CUSTOMER_ID,
65
- parent: null
56
+ customer: options.CUSTOMER_ID
66
57
  })
67
- .then(populateFolders)
68
- .then(folders => cb(null, folders))
69
- .catch(err => cb(err));
58
+ .exec(cb);
70
59
 
71
60
  };
72
61
 
@@ -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.10.0",
3
+ "version": "11.12.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",