aloux-iam 0.0.16 → 0.0.18
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 +16 -4
- package/package.json +1 -1
package/lib/services/auth.js
CHANGED
|
@@ -7,6 +7,7 @@ const bcrypt = require('bcryptjs')
|
|
|
7
7
|
const dayjs = require("dayjs")
|
|
8
8
|
const fs = require("fs")
|
|
9
9
|
const jwt = require("jsonwebtoken")
|
|
10
|
+
const mongoose = require("mongoose")
|
|
10
11
|
|
|
11
12
|
const self = module.exports
|
|
12
13
|
|
|
@@ -157,10 +158,21 @@ self.getMenu = (user) => {
|
|
|
157
158
|
|
|
158
159
|
self.me = async (req, res) => {
|
|
159
160
|
|
|
160
|
-
let user = await User.findOne({ _id: req.user._id }, { "tokens": 0, pwd: 0 }).populate([
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
]).lean()
|
|
161
|
+
// let user = await User.findOne({ _id: req.user._id }, { "tokens": 0, pwd: 0 }).populate([
|
|
162
|
+
// { path: "_business" },
|
|
163
|
+
// { path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] },
|
|
164
|
+
// ]).lean()
|
|
165
|
+
|
|
166
|
+
// Valida que los modelos existan hantes de hacer una consulta con populate
|
|
167
|
+
if (mongoose.modelNames().includes('Business') && mongoose.modelNames().includes('Client')) {
|
|
168
|
+
user = await User.findOne({ _id }).populate([{ path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] },{ path: "_business" }, { path: "_client" }]).select("-pwd -tokens").lean()
|
|
169
|
+
}else if(mongoose.modelNames().includes('Business')){
|
|
170
|
+
user = await User.findOne({ _id }).populate([{ path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] },{ path: "_business" }]).select("-pwd -tokens").lean()
|
|
171
|
+
}else if(mongoose.modelNames().includes('Client')){
|
|
172
|
+
user = await User.findOne({ _id }).populate([{ path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] }, { path: "_client" }]).select("-pwd -tokens").lean()
|
|
173
|
+
} else{
|
|
174
|
+
user = await User.findOne({ _id }).populate([{ path: "_functions", populate: [{ path: "_permissions" }, { path: "_menus" }] }]).select("-pwd -tokens").lean()
|
|
175
|
+
}
|
|
164
176
|
|
|
165
177
|
// Obtener menús y funciones sin repertir y activas
|
|
166
178
|
user.menus = self.getMenu(user)
|