shuttlepro-shared 1.2.61 → 1.2.62
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.
|
@@ -59,15 +59,46 @@ const findUserById = async (id, select = []) => {
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
const findUser = async (filter) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
try {
|
|
63
|
+
const users = await getCachedUsers();
|
|
64
|
+
const user = users.find((u) =>
|
|
65
|
+
Object.entries(filter).every(([key, value]) => {
|
|
66
|
+
if (Array.isArray(value)) {
|
|
67
|
+
return value.includes(u[key]);
|
|
68
|
+
}
|
|
69
|
+
return u[key] === value;
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
if (!user) {
|
|
74
|
+
// Fallback to database if not found in cache
|
|
75
|
+
const dbUser = await User.findOne(filter).lean().exec();
|
|
76
|
+
if (dbUser) await updateCachedUsers(); // Refresh cache if outdated
|
|
77
|
+
return dbUser;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return user;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error("Error finding user:", error);
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const findUsersByFilter = async (filter = {}) => {
|
|
88
|
+
try {
|
|
89
|
+
const users = await getCachedUsers();
|
|
90
|
+
return users.filter((u) =>
|
|
91
|
+
Object.entries(filter).every(([key, value]) => {
|
|
92
|
+
if (Array.isArray(value)) {
|
|
93
|
+
return value.includes(u[key]);
|
|
94
|
+
}
|
|
95
|
+
return u[key] === value;
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error("Error finding users by filter:", error);
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
71
102
|
};
|
|
72
103
|
|
|
73
104
|
const findAllUsers = async (filter = {}) => {
|
|
@@ -111,6 +142,7 @@ module.exports = {
|
|
|
111
142
|
createUser,
|
|
112
143
|
findUserById,
|
|
113
144
|
findUser,
|
|
145
|
+
findUsersByFilter,
|
|
114
146
|
findAllUsers,
|
|
115
147
|
getUserName,
|
|
116
148
|
updateUser,
|
|
@@ -171,15 +171,17 @@ const findUserWorkspaces = async (userId) => {
|
|
|
171
171
|
})
|
|
172
172
|
.lean()
|
|
173
173
|
.exec();
|
|
174
|
-
userRoleWithWorkspaces = userRoleWithWorkspaces
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
174
|
+
userRoleWithWorkspaces = userRoleWithWorkspaces
|
|
175
|
+
?.filter((userRole) => userRole?.workspaceId)
|
|
176
|
+
?.map((ur) => {
|
|
177
|
+
return {
|
|
178
|
+
...ur?.workspaceId,
|
|
179
|
+
id: ur?.workspaceId?._id?.toString(),
|
|
180
|
+
_id: ur?.workspaceId?._id?.toString(),
|
|
181
|
+
role: ur?.roleId?.name || "",
|
|
182
|
+
permissions: ur?.roleId?.modulePermissions?.modules || [],
|
|
183
|
+
};
|
|
184
|
+
});
|
|
183
185
|
if (userRoleWithWorkspaces) {
|
|
184
186
|
await setRedisData(cacheKey, userRoleWithWorkspaces, null, 0);
|
|
185
187
|
}
|
package/config/database.js
CHANGED
package/models/Card.js
CHANGED