aloux-iam 0.0.15 → 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/controllers/user.js +14 -1
- package/lib/services/auth.js +15 -4
- package/package.json +1 -1
package/lib/controllers/user.js
CHANGED
|
@@ -6,6 +6,8 @@ const jwt = require("jsonwebtoken")
|
|
|
6
6
|
const dayjs = require("dayjs")
|
|
7
7
|
const serviceUser = require('../services/user')
|
|
8
8
|
const utils = require('../config/utils')
|
|
9
|
+
const mongoose = require('mongoose');
|
|
10
|
+
|
|
9
11
|
const self = module.exports
|
|
10
12
|
|
|
11
13
|
|
|
@@ -56,8 +58,19 @@ self.updatepassword = async (req, resp) => {
|
|
|
56
58
|
self.get = async (req, res) => {
|
|
57
59
|
try {
|
|
58
60
|
const _id = req.params.USER_ID
|
|
61
|
+
let user = {}
|
|
62
|
+
|
|
63
|
+
// Valida que los modelos existan hantes de hacer una consulta con populate
|
|
64
|
+
if (mongoose.modelNames().includes('Business') && mongoose.modelNames().includes('Client')) {
|
|
65
|
+
user = await User.findOne({ _id }, { pwd: 0 }).populate([{ path: "_functions" },{ path: "_business" }, { path: "_client" }]).select("-pwd -tokens").lean()
|
|
66
|
+
}else if(mongoose.modelNames().includes('Business')){
|
|
67
|
+
user = await User.findOne({ _id }, { pwd: 0 }).populate([{ path: "_functions" },{ path: "_business" }]).select("-pwd -tokens").lean()
|
|
68
|
+
}else if(mongoose.modelNames().includes('Client')){
|
|
69
|
+
user = await User.findOne({ _id }, { pwd: 0 }).populate([{ path: "_functions" }, { path: "_client" }]).select("-pwd -tokens").lean()
|
|
70
|
+
} else{
|
|
71
|
+
user = await User.findOne({ _id }, { pwd: 0 }).populate([{ path: "_functions" }]).select("-pwd -tokens").lean()
|
|
72
|
+
}
|
|
59
73
|
|
|
60
|
-
const user = await User.findOne({ _id }, { pwd: 0 }).populate([{ path: "_functions" },{ path: "_business" }, { path: "_client" }]).select("-pwd -tokens").lean()
|
|
61
74
|
|
|
62
75
|
if (!user)
|
|
63
76
|
res.status(404).send()
|
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)
|