aloux-iam 0.0.16 → 0.0.17

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.
@@ -157,10 +157,21 @@ self.getMenu = (user) => {
157
157
 
158
158
  self.me = async (req, res) => {
159
159
 
160
- let user = await User.findOne({ _id: req.user._id }, { "tokens": 0, pwd: 0 }).populate([
161
- { path: "_business" },
162
- { path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] },
163
- ]).lean()
160
+ // let user = await User.findOne({ _id: req.user._id }, { "tokens": 0, pwd: 0 }).populate([
161
+ // { path: "_business" },
162
+ // { path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] },
163
+ // ]).lean()
164
+
165
+ // Valida que los modelos existan hantes de hacer una consulta con populate
166
+ if (mongoose.modelNames().includes('Business') && mongoose.modelNames().includes('Client')) {
167
+ user = await User.findOne({ _id }).populate([{ path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] },{ path: "_business" }, { path: "_client" }]).select("-pwd -tokens").lean()
168
+ }else if(mongoose.modelNames().includes('Business')){
169
+ user = await User.findOne({ _id }).populate([{ path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] },{ path: "_business" }]).select("-pwd -tokens").lean()
170
+ }else if(mongoose.modelNames().includes('Client')){
171
+ user = await User.findOne({ _id }).populate([{ path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] }, { path: "_client" }]).select("-pwd -tokens").lean()
172
+ } else{
173
+ user = await User.findOne({ _id }).populate([{ path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] }]).select("-pwd -tokens").lean()
174
+ }
164
175
 
165
176
  // Obtener menús y funciones sin repertir y activas
166
177
  user.menus = self.getMenu(user)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aloux-iam",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "Aloux IAM for APIs ",
5
5
  "main": "index.js",
6
6
  "scripts": {