shuttlepro-shared 1.2.63 → 1.2.64
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.
|
@@ -9,6 +9,26 @@ const CACHE_KEY_ALL_MEMBERS = "userroles_all_members";
|
|
|
9
9
|
const CACHE_KEY_USER_WORKSPACE_PREFIX = "userrole_workspace_";
|
|
10
10
|
const CACHE_KEY_USER_PERMISSIONS_PREFIX = "user_permissions_";
|
|
11
11
|
|
|
12
|
+
// Comprehensive cache update method
|
|
13
|
+
const updateAllRelatedCaches = async (userId, workspaceId) => {
|
|
14
|
+
try {
|
|
15
|
+
// Update all members cache
|
|
16
|
+
await updateCachedMembers();
|
|
17
|
+
|
|
18
|
+
// Clear user workspace cache
|
|
19
|
+
if (userId) {
|
|
20
|
+
await clearUserWorkspaceCache(userId);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Clear user permissions cache
|
|
24
|
+
if (workspaceId && userId) {
|
|
25
|
+
await clearUserPermissionsCache(workspaceId, userId);
|
|
26
|
+
}
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error("Error updating related caches:", error);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
12
32
|
// Clear user workspace cache
|
|
13
33
|
const clearUserWorkspaceCache = async (userId) => {
|
|
14
34
|
await setRedisData(
|
|
@@ -50,7 +70,12 @@ const getCachedMembers = async (filter = {}) => {
|
|
|
50
70
|
.lean()
|
|
51
71
|
.exec();
|
|
52
72
|
|
|
53
|
-
await setRedisData(
|
|
73
|
+
await setRedisData(
|
|
74
|
+
cacheKey,
|
|
75
|
+
members?.filter((member) => member?.userId && member?.roleId),
|
|
76
|
+
null,
|
|
77
|
+
0
|
|
78
|
+
);
|
|
54
79
|
}
|
|
55
80
|
|
|
56
81
|
return members;
|
|
@@ -78,23 +103,23 @@ const updateCachedMembers = async (filter = {}) => {
|
|
|
78
103
|
.lean()
|
|
79
104
|
.exec();
|
|
80
105
|
|
|
81
|
-
await setRedisData(
|
|
106
|
+
await setRedisData(
|
|
107
|
+
cacheKey,
|
|
108
|
+
members?.filter((member) => member?.userId && member?.roleId),
|
|
109
|
+
null,
|
|
110
|
+
0
|
|
111
|
+
);
|
|
82
112
|
return members;
|
|
83
113
|
};
|
|
84
114
|
|
|
85
115
|
const createUserRole = async (data) => {
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
// Clear permissions cache if workspaceId exists
|
|
94
|
-
if (data.workspaceId) {
|
|
95
|
-
await clearUserPermissionsCache(data.workspaceId, data.userId);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
116
|
+
const savedRole = await UserRole.create(data);
|
|
117
|
+
|
|
118
|
+
// Update all related caches
|
|
119
|
+
await updateAllRelatedCaches(
|
|
120
|
+
savedRole?.userId?.toString(),
|
|
121
|
+
savedRole?.workspaceId?.toString()
|
|
122
|
+
);
|
|
98
123
|
|
|
99
124
|
return savedRole;
|
|
100
125
|
};
|
|
@@ -109,24 +134,27 @@ const updateUserRole = async (id, data) => {
|
|
|
109
134
|
}).exec();
|
|
110
135
|
|
|
111
136
|
if (updatedRole) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
await clearUserWorkspaceCache(updatedRole.userId);
|
|
115
|
-
// Clear permissions cache if workspaceId exists
|
|
116
|
-
if (updatedRole.workspaceId) {
|
|
117
|
-
await clearUserPermissionsCache(
|
|
118
|
-
updatedRole.workspaceId,
|
|
119
|
-
updatedRole.userId
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
137
|
+
// Update all related caches
|
|
138
|
+
await updateAllRelatedCaches(updatedRole.userId, updatedRole.workspaceId);
|
|
123
139
|
}
|
|
124
140
|
|
|
125
141
|
return updatedRole;
|
|
126
142
|
};
|
|
127
143
|
|
|
128
144
|
const deleteUserRoleByFilter = async (filter) => {
|
|
145
|
+
// Find the role before deleting to get userId and workspaceId
|
|
146
|
+
const roleToDelete = await UserRole.findOne(filter).exec();
|
|
147
|
+
|
|
129
148
|
const deletedRole = await UserRole.findOneAndDelete(filter).exec();
|
|
149
|
+
|
|
150
|
+
if (deletedRole) {
|
|
151
|
+
// Update all related caches
|
|
152
|
+
await updateAllRelatedCaches(
|
|
153
|
+
roleToDelete?.userId,
|
|
154
|
+
roleToDelete?.workspaceId
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
130
158
|
return deletedRole;
|
|
131
159
|
};
|
|
132
160
|
|
|
@@ -138,14 +166,8 @@ const deleteUserRole = async (id) => {
|
|
|
138
166
|
const deletedRole = await UserRole.findByIdAndDelete(id).exec();
|
|
139
167
|
|
|
140
168
|
if (deletedRole) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
await clearUserWorkspaceCache(userId);
|
|
144
|
-
// Clear permissions cache if workspaceId exists
|
|
145
|
-
if (workspaceId) {
|
|
146
|
-
await clearUserPermissionsCache(workspaceId, userId);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
169
|
+
// Update all related caches
|
|
170
|
+
await updateAllRelatedCaches(userId, workspaceId);
|
|
149
171
|
}
|
|
150
172
|
|
|
151
173
|
return deletedRole;
|
|
@@ -360,11 +382,8 @@ const findOneAndUpdateUserRole = async ({
|
|
|
360
382
|
).exec();
|
|
361
383
|
|
|
362
384
|
if (updatedRole) {
|
|
363
|
-
|
|
364
|
-
await
|
|
365
|
-
if (workspaceId) {
|
|
366
|
-
await clearUserPermissionsCache(workspaceId, userId);
|
|
367
|
-
}
|
|
385
|
+
// Update all related caches
|
|
386
|
+
await updateAllRelatedCaches(userId, workspaceId);
|
|
368
387
|
}
|
|
369
388
|
|
|
370
389
|
return updatedRole;
|