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.
- package/lib/services/auth.js +15 -4
- package/package.json +1 -1
package/lib/services/auth.js
CHANGED
|
@@ -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
|
-
|
|
162
|
-
|
|
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)
|