shuttlepro-shared 1.2.36 → 1.2.38

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.
@@ -123,7 +123,9 @@ const deleteUserRole = async (id) => {
123
123
 
124
124
  const findUserWorkspaces = async (userId) => {
125
125
  const cacheKey = `${CACHE_KEY_USER_WORKSPACE_PREFIX}${userId}`;
126
+ console.log(cacheKey, "cacheKey");
126
127
  let userRoleWithWorkspaces = await getDataFromRedisSet(cacheKey);
128
+ console.log(userRoleWithWorkspaces, "from cache");
127
129
  if (!userRoleWithWorkspaces.length) {
128
130
  userRoleWithWorkspaces = await UserRole.find({
129
131
  userId: userId,
@@ -141,9 +143,16 @@ const findUserWorkspaces = async (userId) => {
141
143
  })
142
144
  .lean()
143
145
  .exec();
144
- console.log(userRoleWithWorkspaces, "through db");
145
146
  if (userRoleWithWorkspaces) {
146
- await addArrayToRedisSet(cacheKey, userRoleWithWorkspaces);
147
+ await addArrayToRedisSet(
148
+ cacheKey,
149
+ userRoleWithWorkspaces?.map((x) => {
150
+ return {
151
+ ...x,
152
+ _id: x?._id?.toString(),
153
+ };
154
+ })
155
+ );
147
156
  }
148
157
  }
149
158
  return userRoleWithWorkspaces;
package/config/redis.js CHANGED
@@ -107,10 +107,17 @@ const addDataToRedisSet = async (key, value) => {
107
107
  const addArrayToRedisSet = async (key, value) => {
108
108
  try {
109
109
  await connectRedis();
110
- console.log(key, "key");
110
+
111
111
  const arr = Array.isArray(value) ? value : [value];
112
+
112
113
  console.log(arr, "arr");
113
- await client.sAdd(key, ...arr); // spread values
114
+
115
+ // Convert each item to string (usually JSON)
116
+ const stringifiedArr = arr.map((item) => JSON.stringify(item));
117
+
118
+ console.log(stringifiedArr, "stringifiedArr");
119
+
120
+ await client.sAdd(key, ...stringifiedArr);
114
121
  return true;
115
122
  } catch (err) {
116
123
  console.error("Add Error:", err);
@@ -121,10 +128,16 @@ const addArrayToRedisSet = async (key, value) => {
121
128
  const getDataFromRedisSet = async (key) => {
122
129
  try {
123
130
  await connectRedis();
124
- console.log(key, "key");
125
131
  const values = await client.sMembers(key);
126
- console.log(values, "values");
127
- return values;
132
+
133
+ // Parse each stringified JSON back to object
134
+ return values.map((item) => {
135
+ try {
136
+ return JSON.parse(item);
137
+ } catch (e) {
138
+ return item; // fallback in case it's not JSON
139
+ }
140
+ });
128
141
  } catch (err) {
129
142
  console.error("Get Error:", err);
130
143
  return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shuttlepro-shared",
3
- "version": "1.2.36",
3
+ "version": "1.2.38",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {