shuttlepro-shared 1.3.25 → 1.3.26
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/common/repositories/customerProfile.repository.js +1 -5
- package/common/repositories/userRole.repository.js +5 -2
- package/config/redis.js +72 -73
- package/middlewares/checkPermission/index.js +36 -23
- package/models/Customer.js +1 -0
- package/models/Order.js +11 -0
- package/models/Workspace.js +10 -0
- package/package.json +1 -1
|
@@ -133,10 +133,7 @@ const deleteAllCustomerProfilesByWorkspace = async (workspaceId) => {
|
|
|
133
133
|
await CustomerProfile.deleteMany({ workspaceId }).exec();
|
|
134
134
|
await updateCachedAllCustomerProfiles();
|
|
135
135
|
};
|
|
136
|
-
|
|
137
|
-
const profiles = await CustomerProfile.find(filter).exec().lean();
|
|
138
|
-
return profiles ?? [];
|
|
139
|
-
};
|
|
136
|
+
|
|
140
137
|
module.exports = {
|
|
141
138
|
createCustomerProfile,
|
|
142
139
|
findCustomerProfilesByWorkspaceId,
|
|
@@ -147,5 +144,4 @@ module.exports = {
|
|
|
147
144
|
deleteCustomerProfile,
|
|
148
145
|
deleteAllCustomerProfilesByWorkspace,
|
|
149
146
|
findAllCustomerProfilesByFilter,
|
|
150
|
-
findAllCustomerProfilesByFilterFromDb,
|
|
151
147
|
};
|
|
@@ -2,7 +2,7 @@ const { UserRole } = require("../../models/UserRole");
|
|
|
2
2
|
const { getRedisData, setRedisData } = require("../../config/redis");
|
|
3
3
|
|
|
4
4
|
const defaultSelect =
|
|
5
|
-
"iconUrl thumbUrl name productsCount ordersCount contact email address websiteUrl facebookUrl twitterUrl instagramUrl members defaultModule";
|
|
5
|
+
"iconUrl thumbUrl name productsCount ordersCount contact email address websiteUrl facebookUrl twitterUrl instagramUrl members defaultModule allowedModules";
|
|
6
6
|
|
|
7
7
|
// Cache keys
|
|
8
8
|
const MEMBERS = "members";
|
|
@@ -35,6 +35,7 @@ const updateCachedMembers = async (workspaceId) => {
|
|
|
35
35
|
|
|
36
36
|
const getMembers = async (workspaceId) => {
|
|
37
37
|
let members = await getRedisData(workspaceId, MEMBERS);
|
|
38
|
+
console.log(members, "inside members");
|
|
38
39
|
if (!members || members?.length === 0) {
|
|
39
40
|
members = await UserRole.find({ workspaceId })
|
|
40
41
|
.select("userId role userShift roleId isOwner workspaceId")
|
|
@@ -53,6 +54,7 @@ const getMembers = async (workspaceId) => {
|
|
|
53
54
|
.exec();
|
|
54
55
|
await setRedisData(workspaceId, members, MEMBERS, 3600);
|
|
55
56
|
}
|
|
57
|
+
console.log(members, "inside after members");
|
|
56
58
|
return members;
|
|
57
59
|
};
|
|
58
60
|
|
|
@@ -61,7 +63,8 @@ const getMemberByWorkspaceIdAndUserId = async (workspaceId, userId) => {
|
|
|
61
63
|
return (
|
|
62
64
|
members?.find(
|
|
63
65
|
(member) =>
|
|
64
|
-
member?.workspaceId === workspaceId &&
|
|
66
|
+
member?.workspaceId?.toString() === workspaceId?.toString() &&
|
|
67
|
+
member?.userId?._id?.toString() === userId?.toString()
|
|
65
68
|
) || null
|
|
66
69
|
);
|
|
67
70
|
};
|
package/config/redis.js
CHANGED
|
@@ -8,53 +8,51 @@ const client = createClient({
|
|
|
8
8
|
url: REDIS_URL,
|
|
9
9
|
socket: { reconnectStrategy: (retries) => Math.min(retries * 50, 1000) }, // Exponential backoff
|
|
10
10
|
});
|
|
11
|
-
|
|
12
|
-
// ✅ Create separate Pub/Sub clients
|
|
13
11
|
const publisher = client.duplicate();
|
|
14
12
|
const subscriber = client.duplicate();
|
|
15
13
|
|
|
16
|
-
// ✅
|
|
17
|
-
client
|
|
18
|
-
client.on("
|
|
19
|
-
client.on("
|
|
20
|
-
client.on("
|
|
14
|
+
// ✅ Redis Events
|
|
15
|
+
const handleEvents = (client, label = "Redis") => {
|
|
16
|
+
client.on("error", (err) => console.error(`❌ ${label} Error:`, err));
|
|
17
|
+
client.on("connect", () => console.log(`✅ ${label} Connected`));
|
|
18
|
+
client.on("ready", () => console.log(`🚀 ${label} Ready to use`));
|
|
19
|
+
client.on("end", () => console.log(`❗ ${label} Connection Closed`));
|
|
20
|
+
client.on("reconnecting", () => console.warn(`🔄 ${label} Reconnecting...`));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
handleEvents(client, "Main Redis");
|
|
24
|
+
handleEvents(publisher, "Publisher Redis");
|
|
25
|
+
handleEvents(subscriber, "Subscriber Redis");
|
|
21
26
|
|
|
22
|
-
// ✅ Ensure Redis is connected
|
|
27
|
+
// ✅ Ensure Redis is connected once during app startup
|
|
23
28
|
const connectRedis = async () => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
try {
|
|
30
|
+
if (!client.isOpen) await client.connect();
|
|
31
|
+
if (!publisher.isOpen) await publisher.connect();
|
|
32
|
+
if (!subscriber.isOpen) await subscriber.connect();
|
|
33
|
+
|
|
34
|
+
// Set keyspace events only once
|
|
35
|
+
const config = await client.configGet("notify-keyspace-events");
|
|
36
|
+
if (!config["notify-keyspace-events"]?.includes("Ex")) {
|
|
37
|
+
await client.configSet("notify-keyspace-events", "Ex");
|
|
31
38
|
}
|
|
39
|
+
} catch (err) {
|
|
40
|
+
console.error("❌ Failed to connect to Redis:", err);
|
|
32
41
|
}
|
|
33
|
-
await client.configSet("notify-keyspace-events", "Ex");
|
|
34
42
|
};
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
* ✅ Publish Data to a Channel
|
|
38
|
-
* @param {string} channel - The Redis Pub/Sub channel
|
|
39
|
-
* @param {any} message - The message to send
|
|
40
|
-
*/
|
|
44
|
+
// ✅ Publish Data to a Channel
|
|
41
45
|
const publishToChannel = async (channel, message) => {
|
|
42
46
|
try {
|
|
43
|
-
await connectRedis();
|
|
44
47
|
await publisher.publish(channel, JSON.stringify(message));
|
|
45
48
|
} catch (err) {
|
|
46
49
|
console.error("❌ Error publishing message:", err);
|
|
47
50
|
}
|
|
48
51
|
};
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
* ✅ Subscribe & Listen for Messages
|
|
52
|
-
* @param {string} channel - The Redis Pub/Sub channel
|
|
53
|
-
* @param {function} callback - Callback function to handle messages
|
|
54
|
-
*/
|
|
53
|
+
// ✅ Subscribe & Listen for Messages
|
|
55
54
|
const subscribeToChannel = async (channel, callback, expiry = false) => {
|
|
56
55
|
try {
|
|
57
|
-
await connectRedis();
|
|
58
56
|
await subscriber.subscribe(channel, (message) => {
|
|
59
57
|
if (expiry) callback(message);
|
|
60
58
|
else callback(JSON.parse(message));
|
|
@@ -64,13 +62,7 @@ const subscribeToChannel = async (channel, callback, expiry = false) => {
|
|
|
64
62
|
}
|
|
65
63
|
};
|
|
66
64
|
|
|
67
|
-
|
|
68
|
-
* ✅ Set Data in Redis (Supports String & Hash)
|
|
69
|
-
* @param {string} key - The Redis key
|
|
70
|
-
* @param {any} value - The value to store
|
|
71
|
-
* @param {string|null} field - Optional field for Hash storage
|
|
72
|
-
* @param {number} expiryInSeconds - Expiry time in seconds (default: 3600)
|
|
73
|
-
*/
|
|
65
|
+
// ✅ Set Data in Redis (Supports String & Hash)
|
|
74
66
|
const setRedisData = async (
|
|
75
67
|
key,
|
|
76
68
|
value,
|
|
@@ -78,7 +70,6 @@ const setRedisData = async (
|
|
|
78
70
|
expiryInSeconds = 3600
|
|
79
71
|
) => {
|
|
80
72
|
try {
|
|
81
|
-
await connectRedis();
|
|
82
73
|
const stringifiedValue = JSON.stringify(value);
|
|
83
74
|
let result;
|
|
84
75
|
|
|
@@ -99,43 +90,27 @@ const setRedisData = async (
|
|
|
99
90
|
}
|
|
100
91
|
};
|
|
101
92
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
await connectRedis();
|
|
105
|
-
await client.sAdd(key, value);
|
|
106
|
-
return true;
|
|
107
|
-
} catch (err) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const removeDataFromRedisSet = async (key, value) => {
|
|
113
|
-
try {
|
|
114
|
-
await connectRedis();
|
|
115
|
-
await client.sRem(key, value);
|
|
116
|
-
return true;
|
|
117
|
-
} catch (err) {
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
const isMemberOfRedisSet = async (key, value) => {
|
|
93
|
+
// ✅ Get Data from Redis (Supports String & Hash)
|
|
94
|
+
const getRedisData = async (key, field = null) => {
|
|
122
95
|
try {
|
|
123
|
-
|
|
124
|
-
|
|
96
|
+
const result = field
|
|
97
|
+
? await client.hGet(key, field)
|
|
98
|
+
: await client.get(key);
|
|
99
|
+
return result ? JSON.parse(result) : null;
|
|
125
100
|
} catch (err) {
|
|
126
|
-
console.
|
|
127
|
-
return
|
|
101
|
+
console.error("❌ Error getting Redis data:", err);
|
|
102
|
+
return null;
|
|
128
103
|
}
|
|
129
104
|
};
|
|
130
105
|
/**
|
|
131
|
-
* ✅ Get
|
|
106
|
+
* ✅ Get Expiry Time from Redis
|
|
132
107
|
* @param {string} key - The Redis key
|
|
133
108
|
* @param {string|null} field - Optional field for Hash retrieval
|
|
134
109
|
*/
|
|
135
|
-
const
|
|
110
|
+
const getRedisDataTime = async (key) => {
|
|
136
111
|
try {
|
|
137
112
|
await connectRedis();
|
|
138
|
-
let result =
|
|
113
|
+
let result = await client.ttl(key);
|
|
139
114
|
return result ? JSON.parse(result) : null;
|
|
140
115
|
} catch (err) {
|
|
141
116
|
console.error("❌ Error getting Redis data:", err);
|
|
@@ -143,14 +118,9 @@ const getRedisData = async (key, field = null) => {
|
|
|
143
118
|
}
|
|
144
119
|
};
|
|
145
120
|
|
|
146
|
-
|
|
147
|
-
* ✅ Delete Data from Redis (Supports String & Hash)
|
|
148
|
-
* @param {string} key - The Redis key
|
|
149
|
-
* @param {string|null} field - Optional field for Hash deletion
|
|
150
|
-
*/
|
|
121
|
+
// ✅ Delete Data from Redis (Supports String & Hash)
|
|
151
122
|
const deleteRedisData = async (key, field = null) => {
|
|
152
123
|
try {
|
|
153
|
-
await connectRedis();
|
|
154
124
|
return field ? await client.hDel(key, field) : await client.del(key);
|
|
155
125
|
} catch (err) {
|
|
156
126
|
console.error("❌ Error deleting Redis data:", err);
|
|
@@ -158,9 +128,37 @@ const deleteRedisData = async (key, field = null) => {
|
|
|
158
128
|
}
|
|
159
129
|
};
|
|
160
130
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
131
|
+
// ✅ Redis Set Operations
|
|
132
|
+
const addDataToRedisSet = async (key, value) => {
|
|
133
|
+
try {
|
|
134
|
+
await client.sAdd(key, value);
|
|
135
|
+
return true;
|
|
136
|
+
} catch (err) {
|
|
137
|
+
console.error("❌ Error adding to Redis set:", err);
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const removeDataFromRedisSet = async (key, value) => {
|
|
143
|
+
try {
|
|
144
|
+
await client.sRem(key, value);
|
|
145
|
+
return true;
|
|
146
|
+
} catch (err) {
|
|
147
|
+
console.error("❌ Error removing from Redis set:", err);
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const isMemberOfRedisSet = async (key, value) => {
|
|
153
|
+
try {
|
|
154
|
+
return await client.sIsMember(key, value);
|
|
155
|
+
} catch (err) {
|
|
156
|
+
console.error("❌ Error checking membership in Redis set:", err);
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// ✅ Graceful Shutdown
|
|
164
162
|
const closeClients = async () => {
|
|
165
163
|
if (client.isOpen) await client.quit();
|
|
166
164
|
if (publisher.isOpen) await publisher.quit();
|
|
@@ -184,12 +182,13 @@ module.exports = {
|
|
|
184
182
|
client,
|
|
185
183
|
publisher,
|
|
186
184
|
subscriber,
|
|
185
|
+
connectRedis,
|
|
187
186
|
setRedisData,
|
|
187
|
+
getRedisDataTime,
|
|
188
188
|
getRedisData,
|
|
189
189
|
deleteRedisData,
|
|
190
190
|
publishToChannel,
|
|
191
191
|
subscribeToChannel,
|
|
192
|
-
connectRedis,
|
|
193
192
|
addDataToRedisSet,
|
|
194
193
|
removeDataFromRedisSet,
|
|
195
194
|
isMemberOfRedisSet,
|
|
@@ -31,29 +31,42 @@ exports.checkPermission = async (req, res, next, values) => {
|
|
|
31
31
|
const accessToken = token.split(" ")[1];
|
|
32
32
|
const body = getBodyFromDecodeToken(accessToken);
|
|
33
33
|
if (body) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
34
|
+
req.user = {
|
|
35
|
+
id: body.id,
|
|
36
|
+
type: body.type,
|
|
37
|
+
email: body.email,
|
|
38
|
+
firstName: body.firstName,
|
|
39
|
+
lastName: body.lastName,
|
|
40
|
+
suspended: body.suspended,
|
|
41
|
+
isVerified: body.isVerified,
|
|
42
|
+
role: body.role,
|
|
43
|
+
isMember: body.isMember,
|
|
44
|
+
uuid: body.uuid,
|
|
45
|
+
};
|
|
46
|
+
return next();
|
|
47
|
+
// const { module, action } = values;
|
|
48
|
+
// const moduleObj = getModule(body, module);
|
|
49
|
+
// if (moduleObj && moduleObj.includes(action)) {
|
|
50
|
+
// req.user = {
|
|
51
|
+
// id: body.id,
|
|
52
|
+
// type: body.type,
|
|
53
|
+
// email: body.email,
|
|
54
|
+
// firstName: body.firstName,
|
|
55
|
+
// lastName: body.lastName,
|
|
56
|
+
// suspended: body.suspended,
|
|
57
|
+
// isVerified: body.isVerified,
|
|
58
|
+
// role: body.role,
|
|
59
|
+
// isMember: body.isMember,
|
|
60
|
+
// uuid: body.uuid,
|
|
61
|
+
// };
|
|
62
|
+
// req.currentModulePermission = moduleObj;
|
|
63
|
+
// return next();
|
|
64
|
+
// } else {
|
|
65
|
+
// return res.status(HttpStatusCode.UNAUTHORIZED).json({
|
|
66
|
+
// code: HttpStatusCode.UNAUTHORIZED,
|
|
67
|
+
// message: GenericMessages.PERMISSION_DENIED,
|
|
68
|
+
// });
|
|
69
|
+
// }
|
|
57
70
|
}
|
|
58
71
|
return res.status(HttpStatusCode.UNAUTHORIZED).json({
|
|
59
72
|
code: HttpStatusCode.UNAUTHORIZED,
|
package/models/Customer.js
CHANGED
package/models/Order.js
CHANGED
|
@@ -136,6 +136,14 @@ const OrderSchema = new Schema(
|
|
|
136
136
|
paymentDate: { type: String, default: "" },
|
|
137
137
|
paymentDetails: {},
|
|
138
138
|
},
|
|
139
|
+
merged: {
|
|
140
|
+
status: { type: String, default: "open" },
|
|
141
|
+
webOrderNumbers: [],
|
|
142
|
+
orderNumbers: [],
|
|
143
|
+
localOrderIds: [],
|
|
144
|
+
webOrderIds: [],
|
|
145
|
+
details: [],
|
|
146
|
+
},
|
|
139
147
|
credentials: {},
|
|
140
148
|
ticketId: { type: String, default: "" },
|
|
141
149
|
sender: { type: String, default: "" },
|
|
@@ -159,6 +167,9 @@ const OrderSchema = new Schema(
|
|
|
159
167
|
},
|
|
160
168
|
orderName: { type: String, default: "" },
|
|
161
169
|
totalWeight: { type: String, default: "" },
|
|
170
|
+
currency: {},
|
|
171
|
+
presentedCurrency: {},
|
|
172
|
+
exchangeRate: { type: Number, default: 0 },
|
|
162
173
|
},
|
|
163
174
|
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
164
175
|
);
|
package/models/Workspace.js
CHANGED
|
@@ -292,6 +292,16 @@ const workspaceSchema = new mongoose.Schema(
|
|
|
292
292
|
default: "everyone",
|
|
293
293
|
},
|
|
294
294
|
defaultShift: { type: String, default: "" },
|
|
295
|
+
automationManager: {
|
|
296
|
+
delayThreshold: {
|
|
297
|
+
type: Number,
|
|
298
|
+
default: 5,
|
|
299
|
+
},
|
|
300
|
+
messageCount: {
|
|
301
|
+
type: Number,
|
|
302
|
+
default: 3,
|
|
303
|
+
},
|
|
304
|
+
},
|
|
295
305
|
},
|
|
296
306
|
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
297
307
|
);
|