@dhyasama/totem-models 11.6.0 → 11.8.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.
Files changed (2) hide show
  1. package/lib/Folder.js +24 -6
  2. package/package.json +1 -1
package/lib/Folder.js CHANGED
@@ -12,7 +12,8 @@ module.exports = function(mongoose, config) {
12
12
  id: { type: Schema.ObjectId, required: true },
13
13
  model: { type: String, required: true, enum: ['Organization', 'Person', 'LimitedPartner'] }
14
14
  },
15
- parent: { type: Schema.ObjectId, ref: 'Folder' }
15
+ parent: { type: Schema.ObjectId, ref: 'Folder' },
16
+ documents: [{ type: Schema.ObjectId, ref: 'Document' }]
16
17
  });
17
18
 
18
19
  Folder.statics.modifyById = function(id, update, cb) {
@@ -48,13 +49,30 @@ module.exports = function(mongoose, config) {
48
49
  if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { return cb(new Error('options.CUSTOMER_ID is not a valid ObjectId'), null); }
49
50
 
50
51
  const self = this;
51
- let query = self.find({
52
+
53
+ const populateFolders = async (folders) => {
54
+
55
+ _.each(folders, functon(folder) {
56
+
57
+ await folder.populate('documents').execPopulate();
58
+ const childFolders = await self.find({ parent: folder._id });
59
+ folder.children = await populateFolders(childFolders);
60
+
61
+ });
62
+
63
+ return folders;
64
+
65
+ };
66
+
67
+ self.find({
52
68
  'entity.id': entity.id,
53
69
  'entity.model': entity.model,
54
- customer: options.CUSTOMER_ID
55
- });
56
-
57
- query.exec(cb);
70
+ customer: options.CUSTOMER_ID,
71
+ parent: null
72
+ })
73
+ .then(populateFolders)
74
+ .then(folders => cb(null, folders))
75
+ .catch(err => cb(err));
58
76
 
59
77
  };
60
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "11.6.0",
3
+ "version": "11.8.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",