shuttlepro-shared 1.4.12 → 1.4.14
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/call.repository.js +296 -0
- package/common/repositories/customerProfile.repository.js +1 -7
- package/common/repositories/index.js +3 -0
- package/config/socket.js +249 -30
- package/models/Attribute.js +0 -5
- package/models/Automation.js +0 -32
- package/models/Call.js +192 -0
- package/models/Category.js +0 -5
- package/models/Checkpoint.js +0 -5
- package/models/Customer.js +0 -5
- package/models/CustomerProfile.js +0 -3
- package/models/Location.js +0 -5
- package/models/Order.js +0 -6
- package/models/OrderPdf.js +0 -5
- package/models/OrderProduct.js +0 -5
- package/models/Product.js +0 -5
- package/models/ProductAttachment.js +0 -5
- package/models/ProductAttribute.js +0 -5
- package/models/ProductCategory.js +0 -5
- package/models/ProductTag.js +0 -5
- package/models/ProductVariant.js +0 -5
- package/models/Tag.js +0 -5
- package/models/VariantLocation.js +0 -5
- package/models.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
const Call = require("../../models/Call");
|
|
2
|
+
|
|
3
|
+
class CallRepository {
|
|
4
|
+
constructor() {}
|
|
5
|
+
|
|
6
|
+
async createCall(callData) {
|
|
7
|
+
try {
|
|
8
|
+
const historyEntry = {
|
|
9
|
+
timestamp: new Date(),
|
|
10
|
+
platformTimestamp: callData.platformTimestamp || "",
|
|
11
|
+
action: "created",
|
|
12
|
+
agentId: null,
|
|
13
|
+
direction: "User Initiated",
|
|
14
|
+
details: "Call created from webhook",
|
|
15
|
+
};
|
|
16
|
+
return await Call.create({
|
|
17
|
+
callId: callData.callId,
|
|
18
|
+
callerName: callData.callerName,
|
|
19
|
+
callerNumber: callData.callerNumber,
|
|
20
|
+
receiver: callData.receiver || "",
|
|
21
|
+
platformId: callData.platformId || null,
|
|
22
|
+
workspaceId: callData.workspaceId || null,
|
|
23
|
+
profileId: callData.profileId || null,
|
|
24
|
+
status: callData.status || "pending",
|
|
25
|
+
agentId: callData.agentId || null,
|
|
26
|
+
queuePosition: callData.queuePosition || 0,
|
|
27
|
+
whatsappSdp: callData.whatsappSdp || null,
|
|
28
|
+
metadata: callData.metadata || {},
|
|
29
|
+
tags: callData.tags || [],
|
|
30
|
+
callHistory: [historyEntry],
|
|
31
|
+
});
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error(`❌ Failed to create call ${callData.callId}:`, error);
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async endCall(callId, agentId = null, updateObj = {}, callHistory = {}) {
|
|
39
|
+
try {
|
|
40
|
+
return await Call.findOneAndUpdate(
|
|
41
|
+
{ callId },
|
|
42
|
+
{
|
|
43
|
+
$set: {
|
|
44
|
+
...(updateObj?.status === "ended" ? { endTime: new Date() } : {}),
|
|
45
|
+
...updateObj,
|
|
46
|
+
},
|
|
47
|
+
$push: {
|
|
48
|
+
callHistory: {
|
|
49
|
+
...callHistory,
|
|
50
|
+
timestamp: new Date(),
|
|
51
|
+
agentId,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{ new: true }
|
|
56
|
+
);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error(`❌ Failed to end call ${callId}:`, error);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async updateCall(callId, updateData) {
|
|
64
|
+
try {
|
|
65
|
+
const allowedFields = [
|
|
66
|
+
"status",
|
|
67
|
+
"agentId",
|
|
68
|
+
"callerName",
|
|
69
|
+
"callerNumber",
|
|
70
|
+
"tags",
|
|
71
|
+
"metadata",
|
|
72
|
+
"platformId",
|
|
73
|
+
"workspaceId",
|
|
74
|
+
"profileId",
|
|
75
|
+
"receiver",
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
const filteredUpdate = {};
|
|
79
|
+
Object.keys(updateData).forEach((key) => {
|
|
80
|
+
if (allowedFields.includes(key)) filteredUpdate[key] = updateData[key];
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const updateOps = {
|
|
84
|
+
$set: {
|
|
85
|
+
...filteredUpdate,
|
|
86
|
+
"connectionMetadata.lastHeartbeat": new Date(),
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
if (updateData.status) {
|
|
91
|
+
updateOps.$push = {
|
|
92
|
+
callHistory: {
|
|
93
|
+
timestamp: new Date(),
|
|
94
|
+
action: updateData.status,
|
|
95
|
+
agentId: updateData.agentId || null,
|
|
96
|
+
details:
|
|
97
|
+
updateData.reason || `Status changed to ${updateData.status}`,
|
|
98
|
+
direction: "Agent Initiated",
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return await Call.findOneAndUpdate({ callId }, updateOps, { new: true });
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.error(`❌ Failed to update call ${callId}:`, error);
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async assignCallToAgent(callId, agentId) {
|
|
111
|
+
try {
|
|
112
|
+
return await Call.findOneAndUpdate(
|
|
113
|
+
{ callId, status: { $in: ["pending", "hold"] } },
|
|
114
|
+
{
|
|
115
|
+
$set: {
|
|
116
|
+
agentId,
|
|
117
|
+
status: "active",
|
|
118
|
+
startTime: new Date(),
|
|
119
|
+
"connectionMetadata.lastHeartbeat": new Date(),
|
|
120
|
+
},
|
|
121
|
+
$push: {
|
|
122
|
+
callHistory: {
|
|
123
|
+
timestamp: new Date(),
|
|
124
|
+
action: "answered",
|
|
125
|
+
agentId,
|
|
126
|
+
details: "Call answered by agent",
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
{ new: true }
|
|
131
|
+
);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.error(`❌ Failed to assign call ${callId}:`, error);
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async bulkUpdateCalls(operations) {
|
|
139
|
+
try {
|
|
140
|
+
const bulkOps = operations.map((op) => ({
|
|
141
|
+
updateOne: {
|
|
142
|
+
filter: { callId: op.callId },
|
|
143
|
+
update: {
|
|
144
|
+
$set: {
|
|
145
|
+
...op.updateData,
|
|
146
|
+
"connectionMetadata.lastHeartbeat": new Date(),
|
|
147
|
+
},
|
|
148
|
+
$push: {
|
|
149
|
+
callHistory: {
|
|
150
|
+
timestamp: new Date(),
|
|
151
|
+
action: op.action || "bulk_update",
|
|
152
|
+
agentId: op.agentId,
|
|
153
|
+
details: op.details || "Bulk operation",
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
}));
|
|
159
|
+
return await Call.bulkWrite(bulkOps);
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error("❌ Bulk update failed:", error);
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async moveCallToHoldQueue(callId, reason = "Agent disconnected") {
|
|
167
|
+
try {
|
|
168
|
+
return await Call.findOneAndUpdate(
|
|
169
|
+
{ callId },
|
|
170
|
+
{
|
|
171
|
+
$set: {
|
|
172
|
+
agentId: null,
|
|
173
|
+
status: "hold",
|
|
174
|
+
autoAccepted: true,
|
|
175
|
+
"connectionMetadata.lastHeartbeat": new Date(),
|
|
176
|
+
},
|
|
177
|
+
$push: {
|
|
178
|
+
callHistory: {
|
|
179
|
+
timestamp: new Date(),
|
|
180
|
+
action: "disconnected",
|
|
181
|
+
agentId: null,
|
|
182
|
+
details: reason,
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
{ new: true }
|
|
187
|
+
);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
console.error(`❌ Failed to move call ${callId} to hold queue:`, error);
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/* ----------------- Query Helpers ----------------- */
|
|
195
|
+
|
|
196
|
+
async getCallsByWorkspace(workspaceId, filters = {}) {
|
|
197
|
+
return Call.find({ workspaceId, ...filters })
|
|
198
|
+
.sort({ createdAt: -1 })
|
|
199
|
+
.lean()
|
|
200
|
+
.exec();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async getCallsByAgent(agentId, filters = {}) {
|
|
204
|
+
return Call.find({ agentId, ...filters })
|
|
205
|
+
.sort({ createdAt: -1 })
|
|
206
|
+
.lean()
|
|
207
|
+
.exec();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async getCallsByReceiver(receiver, filters = {}) {
|
|
211
|
+
return Call.find({ receiver, ...filters })
|
|
212
|
+
.sort({ createdAt: -1 })
|
|
213
|
+
.lean()
|
|
214
|
+
.exec();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async getActiveCalls(workspaceId) {
|
|
218
|
+
return Call.find({
|
|
219
|
+
workspaceId,
|
|
220
|
+
status: { $in: ["active", "hold"] },
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async getPendingCalls(workspaceId) {
|
|
225
|
+
return Call.find({ workspaceId, status: "pending" });
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async getStaleCalls(timeoutMinutes = 5) {
|
|
229
|
+
const timeout = new Date(Date.now() - timeoutMinutes * 60 * 1000);
|
|
230
|
+
return Call.find({
|
|
231
|
+
status: { $in: ["active", "hold", "pending"] },
|
|
232
|
+
"connectionMetadata.lastHeartbeat": { $lt: timeout },
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/* ----------------- Reporting & Analytics ----------------- */
|
|
237
|
+
|
|
238
|
+
// Stats grouped by agent
|
|
239
|
+
async getAgentStats(workspaceId, from, to) {
|
|
240
|
+
return Call.aggregate([
|
|
241
|
+
{ $match: { workspaceId, createdAt: { $gte: from, $lte: to } } },
|
|
242
|
+
{
|
|
243
|
+
$group: {
|
|
244
|
+
_id: "$agentId",
|
|
245
|
+
totalCalls: { $sum: 1 },
|
|
246
|
+
answered: {
|
|
247
|
+
$sum: { $cond: [{ $eq: ["$status", "active"] }, 1, 0] },
|
|
248
|
+
},
|
|
249
|
+
ended: {
|
|
250
|
+
$sum: { $cond: [{ $eq: ["$status", "ended"] }, 1, 0] },
|
|
251
|
+
},
|
|
252
|
+
avgDuration: { $avg: "$duration" },
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
]);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Daily call summary
|
|
259
|
+
async getDailySummary(workspaceId, from, to) {
|
|
260
|
+
return Call.aggregate([
|
|
261
|
+
{ $match: { workspaceId, createdAt: { $gte: from, $lte: to } } },
|
|
262
|
+
{
|
|
263
|
+
$group: {
|
|
264
|
+
_id: {
|
|
265
|
+
day: { $dateToString: { format: "%Y-%m-%d", date: "$createdAt" } },
|
|
266
|
+
},
|
|
267
|
+
total: { $sum: 1 },
|
|
268
|
+
ended: {
|
|
269
|
+
$sum: { $cond: [{ $eq: ["$status", "ended"] }, 1, 0] },
|
|
270
|
+
},
|
|
271
|
+
abandoned: {
|
|
272
|
+
$sum: { $cond: [{ $eq: ["$status", "abandoned"] }, 1, 0] },
|
|
273
|
+
},
|
|
274
|
+
avgDuration: { $avg: "$duration" },
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
{ $sort: { "_id.day": 1 } },
|
|
278
|
+
]);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Queue stats
|
|
282
|
+
async getQueueStats(workspaceId) {
|
|
283
|
+
return Call.aggregate([
|
|
284
|
+
{ $match: { workspaceId, status: "hold" } },
|
|
285
|
+
{
|
|
286
|
+
$group: {
|
|
287
|
+
_id: "$receiver",
|
|
288
|
+
count: { $sum: 1 },
|
|
289
|
+
avgQueuePosition: { $avg: "$queuePosition" },
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
]);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
module.exports = new CallRepository();
|
|
@@ -39,12 +39,7 @@ const updateCustomerProfile = async (id, data) => {
|
|
|
39
39
|
}).exec();
|
|
40
40
|
return updated;
|
|
41
41
|
};
|
|
42
|
-
|
|
43
|
-
const result = await CustomerProfile.updateMany(filter, {
|
|
44
|
-
$set: data,
|
|
45
|
-
}).exec();
|
|
46
|
-
return result;
|
|
47
|
-
};
|
|
42
|
+
|
|
48
43
|
const updateCustomerProfileByFilter = async (
|
|
49
44
|
filter,
|
|
50
45
|
data,
|
|
@@ -117,5 +112,4 @@ module.exports = {
|
|
|
117
112
|
findAllCustomerProfilesByFilter,
|
|
118
113
|
findAllCustomerProfilesByFilterFromDb,
|
|
119
114
|
searchCustomerProfilesByName,
|
|
120
|
-
updateManyCustomerProfiles,
|
|
121
115
|
};
|
|
@@ -15,7 +15,9 @@ const notificationSettingsRepository = require("./notificationSettings.repositor
|
|
|
15
15
|
const customerProfileRepository = require("./customerProfile.repository");
|
|
16
16
|
const customerTimelineRepository = require("./customerTimeline.repository");
|
|
17
17
|
const shopRepository = require("./shop.repository");
|
|
18
|
+
const callRepository = require("./call.repository");
|
|
18
19
|
const interactiveRepository = require("./interactive.repository");
|
|
20
|
+
|
|
19
21
|
exports.module = {
|
|
20
22
|
workspaceRepository,
|
|
21
23
|
integrationRepository,
|
|
@@ -34,5 +36,6 @@ exports.module = {
|
|
|
34
36
|
customerProfileRepository,
|
|
35
37
|
customerTimelineRepository,
|
|
36
38
|
shopRepository,
|
|
39
|
+
callRepository,
|
|
37
40
|
interactiveRepository,
|
|
38
41
|
};
|
package/config/socket.js
CHANGED
|
@@ -4,27 +4,46 @@ require("dotenv").config();
|
|
|
4
4
|
|
|
5
5
|
let io;
|
|
6
6
|
const namespaceSockets = {}; // Store different namespace sockets
|
|
7
|
+
const namespaceHandlers = {}; // Store custom handlers for each namespace
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Register custom event handlers for a specific namespace
|
|
11
|
+
* @param {string} namespace - Namespace name
|
|
12
|
+
* @param {Function} handlerFunction - Function that sets up socket event handlers
|
|
13
|
+
*/
|
|
14
|
+
const registerNamespaceHandlers = (namespace, handlerFunction) => {
|
|
15
|
+
namespaceHandlers[namespace] = handlerFunction;
|
|
16
|
+
console.log(`📋 Registered custom handlers for namespace: /${namespace}`);
|
|
17
|
+
};
|
|
7
18
|
|
|
8
19
|
/**
|
|
9
20
|
* Initialize Socket.IO server with namespaces
|
|
10
21
|
* @param {http.Server} server - HTTP server instance
|
|
11
22
|
* @param {string} namespaceParam - Socket namespace name (default: "conversation")
|
|
12
23
|
* @param {string} redisChannel - Redis channel for this namespace (default: "socket_events")
|
|
24
|
+
* @param {Object} options - Additional options for namespace configuration
|
|
25
|
+
* @param {Function} options.customHandlers - Custom socket event handlers for this namespace
|
|
26
|
+
* @param {boolean} options.requireWorkspaceId - Whether workspace ID is required (default: true)
|
|
13
27
|
* @returns {SocketIO.Namespace} - The initialized namespace
|
|
14
28
|
*/
|
|
15
29
|
const initializeSocket = async (
|
|
16
30
|
server,
|
|
17
31
|
namespaceParam = "conversation",
|
|
18
|
-
redisChannel = "socket_events"
|
|
32
|
+
redisChannel = "socket_events",
|
|
33
|
+
options = {}
|
|
19
34
|
) => {
|
|
35
|
+
const {
|
|
36
|
+
customHandlers,
|
|
37
|
+
requireWorkspaceId = true,
|
|
38
|
+
cors = {
|
|
39
|
+
origin: "*",
|
|
40
|
+
methods: ["GET", "POST"],
|
|
41
|
+
},
|
|
42
|
+
} = options;
|
|
43
|
+
|
|
20
44
|
// Initialize Socket.IO server if not already done
|
|
21
45
|
if (!io) {
|
|
22
|
-
io = new Server(server, {
|
|
23
|
-
cors: {
|
|
24
|
-
origin: "*",
|
|
25
|
-
methods: ["GET", "POST"],
|
|
26
|
-
},
|
|
27
|
-
});
|
|
46
|
+
io = new Server(server, { cors });
|
|
28
47
|
console.log("✅ Socket.IO server initialized");
|
|
29
48
|
}
|
|
30
49
|
|
|
@@ -49,21 +68,36 @@ const initializeSocket = async (
|
|
|
49
68
|
await subscriber.subscribe(nsRedisChannel, (messageStr) => {
|
|
50
69
|
try {
|
|
51
70
|
const message = JSON.parse(messageStr);
|
|
52
|
-
const { workspaceId, event, data } = message;
|
|
71
|
+
const { workspaceId, event, data, target } = message;
|
|
53
72
|
|
|
54
73
|
console.log(`📥 Redis message received on ${nsRedisChannel}:`, {
|
|
55
74
|
workspaceId,
|
|
56
75
|
event,
|
|
76
|
+
target,
|
|
57
77
|
});
|
|
58
78
|
|
|
59
|
-
//
|
|
60
|
-
if (
|
|
79
|
+
// Handle different targeting options
|
|
80
|
+
if (target === "broadcast") {
|
|
81
|
+
// Broadcast to all clients in this namespace
|
|
82
|
+
namespace.emit(event, data);
|
|
83
|
+
console.log(
|
|
84
|
+
`📢 Event ${event} broadcasted to all clients in /${namespaceParam}`
|
|
85
|
+
);
|
|
86
|
+
} else if (target && target.startsWith("socket:")) {
|
|
87
|
+
// Target specific socket ID
|
|
88
|
+
const socketId = target.replace("socket:", "");
|
|
89
|
+
namespace.to(socketId).emit(event, data);
|
|
90
|
+
console.log(
|
|
91
|
+
`📢 Event ${event} emitted to socket ${socketId} in /${namespaceParam}`
|
|
92
|
+
);
|
|
93
|
+
} else if (workspaceId) {
|
|
94
|
+
// Emit to specific workspace room in this namespace
|
|
61
95
|
namespace.to(workspaceId).emit(event, data);
|
|
62
96
|
console.log(
|
|
63
97
|
`📢 Event ${event} emitted to workspace ${workspaceId} in /${namespaceParam}`
|
|
64
98
|
);
|
|
65
99
|
} else {
|
|
66
|
-
//
|
|
100
|
+
// Default: broadcast to all clients in this namespace
|
|
67
101
|
namespace.emit(event, data);
|
|
68
102
|
console.log(
|
|
69
103
|
`📢 Event ${event} broadcasted to all clients in /${namespaceParam}`
|
|
@@ -79,20 +113,44 @@ const initializeSocket = async (
|
|
|
79
113
|
|
|
80
114
|
// Handle new socket connections to this namespace
|
|
81
115
|
namespace.on("connection", (socket) => {
|
|
82
|
-
const { workspaceId } = socket.handshake.query;
|
|
116
|
+
const { workspaceId, callId, agentId } = socket.handshake.query;
|
|
83
117
|
|
|
84
|
-
|
|
85
|
-
|
|
118
|
+
// Workspace ID validation (can be disabled for certain namespaces)
|
|
119
|
+
if (requireWorkspaceId && !workspaceId) {
|
|
120
|
+
console.warn(
|
|
121
|
+
`⚠️ Connection rejected: No workspaceId provided for namespace /${namespaceParam}`
|
|
122
|
+
);
|
|
86
123
|
socket.disconnect(true);
|
|
87
124
|
return;
|
|
88
125
|
}
|
|
89
126
|
|
|
90
127
|
console.log(
|
|
91
|
-
`✅ Client connected: ${socket.id} (Workspace: ${
|
|
128
|
+
`✅ Client connected: ${socket.id} (Workspace: ${
|
|
129
|
+
workspaceId || "N/A"
|
|
130
|
+
}, CallId: ${callId || "N/A"}) in /${namespaceParam}`
|
|
92
131
|
);
|
|
93
132
|
|
|
94
|
-
// Join workspace room
|
|
95
|
-
|
|
133
|
+
// Join workspace room if workspaceId is provided
|
|
134
|
+
if (workspaceId) {
|
|
135
|
+
socket.join(workspaceId);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Join additional rooms based on query parameters
|
|
139
|
+
if (callId) {
|
|
140
|
+
socket.join(`call:${callId}`);
|
|
141
|
+
}
|
|
142
|
+
if (agentId) {
|
|
143
|
+
socket.join(`agent:${agentId}`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Store socket metadata
|
|
147
|
+
socket.metadata = {
|
|
148
|
+
workspaceId,
|
|
149
|
+
callId,
|
|
150
|
+
agentId,
|
|
151
|
+
namespace: namespaceParam,
|
|
152
|
+
connectedAt: new Date(),
|
|
153
|
+
};
|
|
96
154
|
|
|
97
155
|
// Send connection confirmation to client
|
|
98
156
|
socket.emit("connected", {
|
|
@@ -100,25 +158,70 @@ const initializeSocket = async (
|
|
|
100
158
|
socketId: socket.id,
|
|
101
159
|
namespace: namespaceParam,
|
|
102
160
|
workspaceId,
|
|
161
|
+
callId,
|
|
162
|
+
agentId,
|
|
103
163
|
});
|
|
104
164
|
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
165
|
+
// Apply custom handlers if provided
|
|
166
|
+
if (customHandlers && typeof customHandlers === "function") {
|
|
167
|
+
try {
|
|
168
|
+
customHandlers(socket, namespace);
|
|
169
|
+
console.log(
|
|
170
|
+
`📋 Applied custom handlers for socket ${socket.id} in /${namespaceParam}`
|
|
171
|
+
);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.error(
|
|
174
|
+
`❌ Error applying custom handlers for socket ${socket.id}:`,
|
|
175
|
+
error
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Apply registered namespace handlers
|
|
181
|
+
if (namespaceHandlers[namespaceParam]) {
|
|
182
|
+
try {
|
|
183
|
+
namespaceHandlers[namespaceParam](socket, namespace);
|
|
184
|
+
console.log(
|
|
185
|
+
`📋 Applied registered handlers for socket ${socket.id} in /${namespaceParam}`
|
|
186
|
+
);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
console.error(
|
|
189
|
+
`❌ Error applying registered handlers for socket ${socket.id}:`,
|
|
190
|
+
error
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Default event handlers for backward compatibility
|
|
196
|
+
setupDefaultHandlers(socket, namespace, namespaceParam);
|
|
110
197
|
|
|
111
198
|
// Handle disconnect
|
|
112
199
|
socket.on("disconnect", (reason) => {
|
|
113
200
|
console.log(
|
|
114
|
-
`❌ Client disconnected: ${socket.id} (Workspace: ${
|
|
201
|
+
`❌ Client disconnected: ${socket.id} (Workspace: ${
|
|
202
|
+
workspaceId || "N/A"
|
|
203
|
+
}, Reason: ${reason}) from /${namespaceParam}`
|
|
115
204
|
);
|
|
116
|
-
|
|
205
|
+
|
|
206
|
+
// Leave all rooms
|
|
207
|
+
if (workspaceId) socket.leave(workspaceId);
|
|
208
|
+
if (callId) socket.leave(`call:${callId}`);
|
|
209
|
+
if (agentId) socket.leave(`agent:${agentId}`);
|
|
210
|
+
|
|
211
|
+
// Emit disconnect event to namespace for cleanup
|
|
212
|
+
namespace.emit("client_disconnected", {
|
|
213
|
+
socketId: socket.id,
|
|
214
|
+
metadata: socket.metadata,
|
|
215
|
+
reason,
|
|
216
|
+
});
|
|
117
217
|
});
|
|
118
218
|
|
|
119
219
|
// Handle errors
|
|
120
220
|
socket.on("error", (error) => {
|
|
121
|
-
console.error(
|
|
221
|
+
console.error(
|
|
222
|
+
`❌ Socket error for ${socket.id} in /${namespaceParam}:`,
|
|
223
|
+
error
|
|
224
|
+
);
|
|
122
225
|
});
|
|
123
226
|
});
|
|
124
227
|
|
|
@@ -128,15 +231,64 @@ const initializeSocket = async (
|
|
|
128
231
|
return namespace;
|
|
129
232
|
};
|
|
130
233
|
|
|
234
|
+
/**
|
|
235
|
+
* Setup default event handlers for backward compatibility
|
|
236
|
+
* @param {Socket} socket - Socket.IO socket instance
|
|
237
|
+
* @param {Namespace} namespace - Socket.IO namespace instance
|
|
238
|
+
* @param {string} namespaceParam - Namespace name
|
|
239
|
+
*/
|
|
240
|
+
const setupDefaultHandlers = (socket, namespace, namespaceParam) => {
|
|
241
|
+
// Handle custom events from clients (backward compatibility)
|
|
242
|
+
socket.on("client_event", (data) => {
|
|
243
|
+
console.log(
|
|
244
|
+
`📥 Client event from ${socket.id} in /${namespaceParam}:`,
|
|
245
|
+
data
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
// Emit to Redis for other instances to handle
|
|
249
|
+
sendEventToServer({
|
|
250
|
+
workspaceId: socket.metadata.workspaceId,
|
|
251
|
+
event: "client_event_received",
|
|
252
|
+
data: {
|
|
253
|
+
socketId: socket.id,
|
|
254
|
+
originalData: data,
|
|
255
|
+
metadata: socket.metadata,
|
|
256
|
+
},
|
|
257
|
+
namespace: namespaceParam,
|
|
258
|
+
}).catch((err) => {
|
|
259
|
+
console.error(`❌ Error publishing client_event to Redis:`, err);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// Handle room join requests
|
|
264
|
+
socket.on("join_room", (roomName) => {
|
|
265
|
+
if (roomName && typeof roomName === "string") {
|
|
266
|
+
socket.join(roomName);
|
|
267
|
+
socket.emit("room_joined", { room: roomName, success: true });
|
|
268
|
+
console.log(`📥 Socket ${socket.id} joined room: ${roomName}`);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// Handle room leave requests
|
|
273
|
+
socket.on("leave_room", (roomName) => {
|
|
274
|
+
if (roomName && typeof roomName === "string") {
|
|
275
|
+
socket.leave(roomName);
|
|
276
|
+
socket.emit("room_left", { room: roomName, success: true });
|
|
277
|
+
console.log(`📤 Socket ${socket.id} left room: ${roomName}`);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
|
|
131
282
|
/**
|
|
132
283
|
* Send event to clients via Redis pub/sub
|
|
133
284
|
* @param {object} params - Event parameters
|
|
134
|
-
* @param {string} params.workspaceId - Target workspace ID
|
|
285
|
+
* @param {string} [params.workspaceId] - Target workspace ID
|
|
135
286
|
* @param {string} params.event - Event name
|
|
136
287
|
* @param {any} params.data - Event data payload
|
|
137
288
|
* @param {string} [params.namespace="conversation"] - Target namespace
|
|
138
289
|
* @param {string} [params.redisChannel="socket_events"] - Base Redis channel
|
|
139
|
-
* @
|
|
290
|
+
* @param {string} [params.target] - Specific target (broadcast, socket:socketId, etc.)
|
|
291
|
+
* @returns {Promise<boolean>}
|
|
140
292
|
*/
|
|
141
293
|
const sendEventToServer = async ({
|
|
142
294
|
workspaceId,
|
|
@@ -144,6 +296,7 @@ const sendEventToServer = async ({
|
|
|
144
296
|
data,
|
|
145
297
|
namespace = "conversation",
|
|
146
298
|
redisChannel = "socket_events",
|
|
299
|
+
target,
|
|
147
300
|
}) => {
|
|
148
301
|
try {
|
|
149
302
|
// Create namespace-specific Redis channel
|
|
@@ -153,13 +306,21 @@ const sendEventToServer = async ({
|
|
|
153
306
|
await connectRedis();
|
|
154
307
|
|
|
155
308
|
// Create message payload
|
|
156
|
-
const message = JSON.stringify({
|
|
309
|
+
const message = JSON.stringify({
|
|
310
|
+
workspaceId,
|
|
311
|
+
event,
|
|
312
|
+
data,
|
|
313
|
+
target,
|
|
314
|
+
timestamp: new Date().toISOString(),
|
|
315
|
+
});
|
|
157
316
|
|
|
158
317
|
// Publish to Redis
|
|
159
318
|
await publisher.publish(nsRedisChannel, message);
|
|
160
319
|
|
|
161
320
|
console.log(
|
|
162
|
-
`📢 Event published to Redis channel ${nsRedisChannel}: ${event} (Workspace: ${
|
|
321
|
+
`📢 Event published to Redis channel ${nsRedisChannel}: ${event} (Workspace: ${
|
|
322
|
+
workspaceId || "N/A"
|
|
323
|
+
}, Target: ${target || "default"})`
|
|
163
324
|
);
|
|
164
325
|
|
|
165
326
|
return true;
|
|
@@ -169,4 +330,62 @@ const sendEventToServer = async ({
|
|
|
169
330
|
}
|
|
170
331
|
};
|
|
171
332
|
|
|
172
|
-
|
|
333
|
+
/**
|
|
334
|
+
* Get a specific namespace instance
|
|
335
|
+
* @param {string} namespace - Namespace name
|
|
336
|
+
* @returns {SocketIO.Namespace|null} - Namespace instance or null if not found
|
|
337
|
+
*/
|
|
338
|
+
const getNamespace = (namespace) => {
|
|
339
|
+
return namespaceSockets[namespace] || null;
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Get all active namespaces
|
|
344
|
+
* @returns {Object} - Object containing all active namespaces
|
|
345
|
+
*/
|
|
346
|
+
const getAllNamespaces = () => {
|
|
347
|
+
return { ...namespaceSockets };
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Get Socket.IO server instance
|
|
352
|
+
* @returns {SocketIO.Server|null} - Server instance or null if not initialized
|
|
353
|
+
*/
|
|
354
|
+
const getSocketServer = () => {
|
|
355
|
+
return io || null;
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Emit event to specific room in a namespace
|
|
360
|
+
* @param {string} namespace - Namespace name
|
|
361
|
+
* @param {string} room - Room name
|
|
362
|
+
* @param {string} event - Event name
|
|
363
|
+
* @param {any} data - Event data
|
|
364
|
+
* @returns {boolean} - Success status
|
|
365
|
+
*/
|
|
366
|
+
const emitToRoom = (namespace, room, event, data) => {
|
|
367
|
+
try {
|
|
368
|
+
const ns = namespaceSockets[namespace];
|
|
369
|
+
if (!ns) {
|
|
370
|
+
console.warn(`❌ Namespace /${namespace} not found`);
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
ns.to(room).emit(event, data);
|
|
375
|
+
console.log(`📢 Event ${event} emitted to room ${room} in /${namespace}`);
|
|
376
|
+
return true;
|
|
377
|
+
} catch (error) {
|
|
378
|
+
console.error(`❌ Error emitting to room ${room} in /${namespace}:`, error);
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
module.exports = {
|
|
384
|
+
initializeSocket,
|
|
385
|
+
sendEventToServer,
|
|
386
|
+
registerNamespaceHandlers,
|
|
387
|
+
getNamespace,
|
|
388
|
+
getAllNamespaces,
|
|
389
|
+
getSocketServer,
|
|
390
|
+
emitToRoom,
|
|
391
|
+
};
|
package/models/Attribute.js
CHANGED
|
@@ -10,11 +10,6 @@ const AttributeSchema = new Schema(
|
|
|
10
10
|
ref: "Workspace",
|
|
11
11
|
default: null,
|
|
12
12
|
},
|
|
13
|
-
websiteId: {
|
|
14
|
-
type: Schema.Types.ObjectId,
|
|
15
|
-
ref: "Website",
|
|
16
|
-
default: null,
|
|
17
|
-
},
|
|
18
13
|
oldId: { type: String, default: "" },
|
|
19
14
|
createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
20
15
|
updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
package/models/Automation.js
CHANGED
|
@@ -55,32 +55,6 @@ const AutomationAction = new Schema({
|
|
|
55
55
|
templateId: descriptionJoin,
|
|
56
56
|
delay: defaultStringType,
|
|
57
57
|
},
|
|
58
|
-
ticketList: {
|
|
59
|
-
enabled: { type: Boolean, default: false },
|
|
60
|
-
templateId: descriptionJoin,
|
|
61
|
-
delay: defaultStringType,
|
|
62
|
-
ticketList: [
|
|
63
|
-
{
|
|
64
|
-
id: {
|
|
65
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
66
|
-
ref: "Column",
|
|
67
|
-
required: true,
|
|
68
|
-
},
|
|
69
|
-
title: {
|
|
70
|
-
type: String,
|
|
71
|
-
required: true,
|
|
72
|
-
},
|
|
73
|
-
name: {
|
|
74
|
-
type: String,
|
|
75
|
-
required: true,
|
|
76
|
-
},
|
|
77
|
-
type: {
|
|
78
|
-
type: String,
|
|
79
|
-
required: true,
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
},
|
|
84
58
|
markAsSpam: {
|
|
85
59
|
enabled: { type: Boolean, default: false },
|
|
86
60
|
},
|
|
@@ -90,10 +64,6 @@ const AutomationAction = new Schema({
|
|
|
90
64
|
hideComment: {
|
|
91
65
|
enabled: { type: Boolean, default: false },
|
|
92
66
|
},
|
|
93
|
-
futureRestriction: {
|
|
94
|
-
enabled: { type: Boolean, default: false },
|
|
95
|
-
action: { type: String, default: "" },
|
|
96
|
-
},
|
|
97
67
|
closeChat: {
|
|
98
68
|
enabled: { type: Boolean, default: false },
|
|
99
69
|
},
|
|
@@ -199,7 +169,6 @@ const AutomationCondition = new Schema({
|
|
|
199
169
|
"shift",
|
|
200
170
|
"newCommentPost",
|
|
201
171
|
"profile",
|
|
202
|
-
"moveTicket",
|
|
203
172
|
],
|
|
204
173
|
},
|
|
205
174
|
keyValue: {
|
|
@@ -224,7 +193,6 @@ const AutomationCondition = new Schema({
|
|
|
224
193
|
"orderPublish",
|
|
225
194
|
"newCommentPost",
|
|
226
195
|
"profile",
|
|
227
|
-
"moveTicket",
|
|
228
196
|
],
|
|
229
197
|
},
|
|
230
198
|
subKeyValue: {
|
package/models/Call.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
const { Schema } = mongoose;
|
|
3
|
+
|
|
4
|
+
const callSchema = new mongoose.Schema(
|
|
5
|
+
{
|
|
6
|
+
workspaceId: { type: Schema.Types.ObjectId, ref: "Workspace" },
|
|
7
|
+
callId: {
|
|
8
|
+
type: String,
|
|
9
|
+
required: true,
|
|
10
|
+
unique: true,
|
|
11
|
+
index: true,
|
|
12
|
+
},
|
|
13
|
+
callerName: {
|
|
14
|
+
type: String,
|
|
15
|
+
required: true,
|
|
16
|
+
},
|
|
17
|
+
callerNumber: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: true,
|
|
20
|
+
index: true,
|
|
21
|
+
},
|
|
22
|
+
profileId: { type: Schema.Types.ObjectId, ref: "Profile" },
|
|
23
|
+
receiver: {
|
|
24
|
+
type: String,
|
|
25
|
+
default: "",
|
|
26
|
+
},
|
|
27
|
+
platformId: {
|
|
28
|
+
type: Schema.Types.ObjectId,
|
|
29
|
+
ref: "Integration",
|
|
30
|
+
default: null,
|
|
31
|
+
},
|
|
32
|
+
type: { type: String, default: "inbound" },
|
|
33
|
+
status: {
|
|
34
|
+
type: String,
|
|
35
|
+
enum: ["pending", "hold", "active", "ended", "disconnected", "abandoned"],
|
|
36
|
+
default: "pending",
|
|
37
|
+
index: true,
|
|
38
|
+
},
|
|
39
|
+
queuePosition: {
|
|
40
|
+
type: Number,
|
|
41
|
+
default: 0,
|
|
42
|
+
},
|
|
43
|
+
agentId: {
|
|
44
|
+
type: String,
|
|
45
|
+
default: null,
|
|
46
|
+
index: true,
|
|
47
|
+
},
|
|
48
|
+
startTime: {
|
|
49
|
+
type: Date,
|
|
50
|
+
default: null,
|
|
51
|
+
},
|
|
52
|
+
endTime: {
|
|
53
|
+
type: Date,
|
|
54
|
+
default: null,
|
|
55
|
+
},
|
|
56
|
+
duration: {
|
|
57
|
+
type: Number,
|
|
58
|
+
default: 0,
|
|
59
|
+
},
|
|
60
|
+
whatsappSdp: {
|
|
61
|
+
type: String,
|
|
62
|
+
default: null,
|
|
63
|
+
},
|
|
64
|
+
browserSdp: {
|
|
65
|
+
type: String,
|
|
66
|
+
default: null,
|
|
67
|
+
},
|
|
68
|
+
callHistory: [
|
|
69
|
+
{
|
|
70
|
+
action: {
|
|
71
|
+
type: String,
|
|
72
|
+
enum: [
|
|
73
|
+
"created",
|
|
74
|
+
"answered",
|
|
75
|
+
"held",
|
|
76
|
+
"unheld",
|
|
77
|
+
"transferred",
|
|
78
|
+
"ended",
|
|
79
|
+
"disconnected",
|
|
80
|
+
"reconnected",
|
|
81
|
+
"abandoned",
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
direction: String, // USER INITIATED // AGENT INITIATED
|
|
85
|
+
agentId: String, // agent id
|
|
86
|
+
details: String, // "Status changed to hold"
|
|
87
|
+
startTime: String, // platform start time
|
|
88
|
+
endTime: String, // platform endTime time
|
|
89
|
+
duration: Number, // platform call duration
|
|
90
|
+
timestamp: {
|
|
91
|
+
// system timestamp
|
|
92
|
+
type: Date,
|
|
93
|
+
default: Date.now,
|
|
94
|
+
},
|
|
95
|
+
platformTimestamp: String, // platformtimestamp
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
metadata: {},
|
|
99
|
+
tags: [],
|
|
100
|
+
connectionMetadata: {
|
|
101
|
+
browserConnectionState: {
|
|
102
|
+
type: String,
|
|
103
|
+
default: "new",
|
|
104
|
+
},
|
|
105
|
+
whatsappConnectionState: {
|
|
106
|
+
type: String,
|
|
107
|
+
default: "new",
|
|
108
|
+
},
|
|
109
|
+
lastHeartbeat: {
|
|
110
|
+
type: Date,
|
|
111
|
+
default: Date.now,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
rating: {
|
|
115
|
+
type: Number,
|
|
116
|
+
default: 0,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
timestamps: true,
|
|
121
|
+
collection: "calls",
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
// Indexes for performance
|
|
126
|
+
callSchema.index({ status: 1, createdAt: 1 });
|
|
127
|
+
callSchema.index({ agentId: 1, status: 1 });
|
|
128
|
+
callSchema.index({ callerNumber: 1, createdAt: -1 });
|
|
129
|
+
callSchema.index({ isOnHold: 1, status: 1 });
|
|
130
|
+
|
|
131
|
+
// Virtual for call duration calculation
|
|
132
|
+
callSchema.virtual("currentDuration").get(function () {
|
|
133
|
+
if (this.startTime) {
|
|
134
|
+
const endTime = this.endTime || new Date();
|
|
135
|
+
return Math.floor((endTime - this.startTime) / 1000);
|
|
136
|
+
}
|
|
137
|
+
return 0;
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Methods
|
|
141
|
+
callSchema.methods.addToHistory = function (
|
|
142
|
+
action,
|
|
143
|
+
agentId = null,
|
|
144
|
+
details = null
|
|
145
|
+
) {
|
|
146
|
+
this.callHistory.push({
|
|
147
|
+
action,
|
|
148
|
+
agentId,
|
|
149
|
+
details,
|
|
150
|
+
timestamp: new Date(),
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
callSchema.methods.updateHeartbeat = function () {
|
|
155
|
+
this.connectionMetadata.lastHeartbeat = new Date();
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
callSchema.methods.isStale = function (timeoutMinutes = 5) {
|
|
159
|
+
const timeout = timeoutMinutes * 60 * 1000; // Convert to milliseconds
|
|
160
|
+
return new Date() - this.connectionMetadata.lastHeartbeat > timeout;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// Static methods
|
|
164
|
+
callSchema.statics.getActiveCallsForAgent = function (agentId) {
|
|
165
|
+
return this.find({
|
|
166
|
+
agentId,
|
|
167
|
+
status: { $in: ["active", "hold"] },
|
|
168
|
+
}).sort({ createdAt: 1 });
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
callSchema.statics.getHoldQueue = function () {
|
|
172
|
+
return this.find({
|
|
173
|
+
status: "hold",
|
|
174
|
+
agentId: null,
|
|
175
|
+
}).sort({ createdAt: 1 });
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
callSchema.statics.getPendingCalls = function () {
|
|
179
|
+
return this.find({
|
|
180
|
+
status: "pending",
|
|
181
|
+
}).sort({ createdAt: 1 });
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
callSchema.statics.getStaleConnections = function (timeoutMinutes = 5) {
|
|
185
|
+
const timeout = new Date(Date.now() - timeoutMinutes * 60 * 1000);
|
|
186
|
+
return this.find({
|
|
187
|
+
status: { $in: ["active", "hold", "pending"] },
|
|
188
|
+
"connectionMetadata.lastHeartbeat": { $lt: timeout },
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
module.exports = mongoose.model("Call", callSchema);
|
package/models/Category.js
CHANGED
|
@@ -11,11 +11,6 @@ const CategorySchema = new Schema(
|
|
|
11
11
|
ref: "Workspace",
|
|
12
12
|
default: null,
|
|
13
13
|
},
|
|
14
|
-
websiteId: {
|
|
15
|
-
type: Schema.Types.ObjectId,
|
|
16
|
-
ref: "Website",
|
|
17
|
-
default: null,
|
|
18
|
-
},
|
|
19
14
|
oldId: { type: String, default: "" },
|
|
20
15
|
webCategoryId: { type: Number, default: null },
|
|
21
16
|
parentId: { type: Schema.Types.ObjectId, ref: "Category", default: null },
|
package/models/Checkpoint.js
CHANGED
|
@@ -14,11 +14,6 @@ const CheckpointSchema = new Schema(
|
|
|
14
14
|
ref: "Workspace",
|
|
15
15
|
default: null,
|
|
16
16
|
},
|
|
17
|
-
websiteId: {
|
|
18
|
-
type: Schema.Types.ObjectId,
|
|
19
|
-
ref: "Website",
|
|
20
|
-
default: null,
|
|
21
|
-
},
|
|
22
17
|
},
|
|
23
18
|
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
24
19
|
);
|
package/models/Customer.js
CHANGED
|
@@ -18,11 +18,6 @@ const CustomerSchema = new Schema(
|
|
|
18
18
|
ref: "Workspace",
|
|
19
19
|
default: null,
|
|
20
20
|
},
|
|
21
|
-
websiteId: {
|
|
22
|
-
type: Schema.Types.ObjectId,
|
|
23
|
-
ref: "Website",
|
|
24
|
-
default: null,
|
|
25
|
-
},
|
|
26
21
|
isBlackListed: { type: Boolean, default: false },
|
|
27
22
|
createdBy: {
|
|
28
23
|
type: Schema.Types.ObjectId,
|
|
@@ -24,9 +24,6 @@ const CustomerProfileSchema = new Schema(
|
|
|
24
24
|
default: null,
|
|
25
25
|
},
|
|
26
26
|
body: {},
|
|
27
|
-
blocked: { type: Boolean, default: false }, // To Block User (Current Automation case)
|
|
28
|
-
hideComments: { type: Boolean, default: false }, // For Hide Comment Check
|
|
29
|
-
deleteComments: { type: Boolean, default: false }, // For Delete Comment Check
|
|
30
27
|
},
|
|
31
28
|
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
32
29
|
);
|
package/models/Location.js
CHANGED
|
@@ -14,11 +14,6 @@ const LocationSchema = new Schema(
|
|
|
14
14
|
oldId: { type: String, default: "" },
|
|
15
15
|
webLocationId: { type: Number, default: null },
|
|
16
16
|
bcLocationId: { type: String, default: "" },
|
|
17
|
-
websiteId: {
|
|
18
|
-
type: Schema.Types.ObjectId,
|
|
19
|
-
ref: "Website",
|
|
20
|
-
default: null,
|
|
21
|
-
},
|
|
22
17
|
workspaceId: {
|
|
23
18
|
type: Schema.Types.ObjectId,
|
|
24
19
|
ref: "Workspace",
|
package/models/Order.js
CHANGED
|
@@ -103,11 +103,6 @@ const OrderSchema = new Schema(
|
|
|
103
103
|
ref: "Workspace",
|
|
104
104
|
default: null,
|
|
105
105
|
},
|
|
106
|
-
websiteId: {
|
|
107
|
-
type: Schema.Types.ObjectId,
|
|
108
|
-
ref: "Website",
|
|
109
|
-
default: null,
|
|
110
|
-
},
|
|
111
106
|
orderType: { type: String, default: "" },
|
|
112
107
|
barCode: { type: String, default: "" },
|
|
113
108
|
quantity: { type: Number, default: 0 },
|
|
@@ -228,7 +223,6 @@ const markOrUnMarkOrderAsDuplicate = async (doc) => {
|
|
|
228
223
|
const phoneRegex = getPhoneRegex(doc?.customerPhone);
|
|
229
224
|
let orders = await Order.find({
|
|
230
225
|
workspaceId: doc?.workspaceId,
|
|
231
|
-
websiteId: doc?.websiteId,
|
|
232
226
|
isDeleted: false,
|
|
233
227
|
statusType: "pending",
|
|
234
228
|
customerPhone: phoneRegex,
|
package/models/OrderPdf.js
CHANGED
|
@@ -20,11 +20,6 @@ const OrderPdfScehma = new mongoose.Schema(
|
|
|
20
20
|
ref: "Workspace",
|
|
21
21
|
default: null,
|
|
22
22
|
},
|
|
23
|
-
websiteId: {
|
|
24
|
-
type: Schema.Types.ObjectId,
|
|
25
|
-
ref: "Website",
|
|
26
|
-
default: null,
|
|
27
|
-
},
|
|
28
23
|
createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
29
24
|
updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
30
25
|
},
|
package/models/OrderProduct.js
CHANGED
|
@@ -31,11 +31,6 @@ const OrderProductSchema = new Schema(
|
|
|
31
31
|
ref: "Workspace",
|
|
32
32
|
default: null,
|
|
33
33
|
},
|
|
34
|
-
websiteId: {
|
|
35
|
-
type: Schema.Types.ObjectId,
|
|
36
|
-
ref: "Website",
|
|
37
|
-
default: null,
|
|
38
|
-
},
|
|
39
34
|
},
|
|
40
35
|
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
41
36
|
);
|
package/models/Product.js
CHANGED
|
@@ -31,11 +31,6 @@ const ProductSchema = new Schema(
|
|
|
31
31
|
type: Schema.Types.ObjectId,
|
|
32
32
|
ref: "Workspace",
|
|
33
33
|
default: null,
|
|
34
|
-
},
|
|
35
|
-
websiteId: {
|
|
36
|
-
type: Schema.Types.ObjectId,
|
|
37
|
-
ref: "Website",
|
|
38
|
-
default: null,
|
|
39
34
|
},
|
|
40
35
|
storeType: { type: String, default: "LOCAL" },
|
|
41
36
|
isDeleted: { type: Boolean, default: false },
|
|
@@ -22,11 +22,6 @@ const ProductAttachmentSchema = new Schema(
|
|
|
22
22
|
ref: "Workspace",
|
|
23
23
|
default: null,
|
|
24
24
|
},
|
|
25
|
-
websiteId: {
|
|
26
|
-
type: Schema.Types.ObjectId,
|
|
27
|
-
ref: "Website",
|
|
28
|
-
default: null,
|
|
29
|
-
},
|
|
30
25
|
height: { type: Number, default: 0 },
|
|
31
26
|
variantIds: [
|
|
32
27
|
{ type: Schema.Types.ObjectId, ref: "ProductVariant", default: null },
|
|
@@ -16,11 +16,6 @@ const ProductAttributeSchema = new mongoose.Schema(
|
|
|
16
16
|
ref: "Workspace",
|
|
17
17
|
default: null,
|
|
18
18
|
},
|
|
19
|
-
websiteId: {
|
|
20
|
-
type: Schema.Types.ObjectId,
|
|
21
|
-
ref: "Website",
|
|
22
|
-
default: null,
|
|
23
|
-
},
|
|
24
19
|
isDeleted: { type: Boolean, default: false },
|
|
25
20
|
position: { type: String, default: "1" },
|
|
26
21
|
},
|
|
@@ -11,11 +11,6 @@ const ProductCategorySchema = new Schema(
|
|
|
11
11
|
ref: "Workspace",
|
|
12
12
|
default: null,
|
|
13
13
|
},
|
|
14
|
-
websiteId: {
|
|
15
|
-
type: Schema.Types.ObjectId,
|
|
16
|
-
ref: "Website",
|
|
17
|
-
default: null,
|
|
18
|
-
},
|
|
19
14
|
createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
20
15
|
updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
21
16
|
isDeleted: { type: Boolean, default: false },
|
package/models/ProductTag.js
CHANGED
|
@@ -11,11 +11,6 @@ const ProductTagSchema = new Schema(
|
|
|
11
11
|
ref: "Workspace",
|
|
12
12
|
default: null,
|
|
13
13
|
},
|
|
14
|
-
websiteId: {
|
|
15
|
-
type: Schema.Types.ObjectId,
|
|
16
|
-
ref: "Website",
|
|
17
|
-
default: null,
|
|
18
|
-
},
|
|
19
14
|
createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
20
15
|
updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
21
16
|
isDeleted: { type: Boolean, default: false },
|
package/models/ProductVariant.js
CHANGED
|
@@ -17,11 +17,6 @@ const ProductVariantSchema = new Schema(
|
|
|
17
17
|
ref: "Workspace",
|
|
18
18
|
default: null,
|
|
19
19
|
},
|
|
20
|
-
websiteId: {
|
|
21
|
-
type: Schema.Types.ObjectId,
|
|
22
|
-
ref: "Website",
|
|
23
|
-
default: null,
|
|
24
|
-
},
|
|
25
20
|
webVariantId: { type: Number, default: null },
|
|
26
21
|
inventoryPolicy: { type: String, default: "deny" }, //deny,continue
|
|
27
22
|
taxable: { type: Boolean, default: false },
|
package/models/Tag.js
CHANGED
|
@@ -8,11 +8,6 @@ const TagSchema = new Schema(
|
|
|
8
8
|
ref: "Workspace",
|
|
9
9
|
default: null,
|
|
10
10
|
},
|
|
11
|
-
websiteId: {
|
|
12
|
-
type: Schema.Types.ObjectId,
|
|
13
|
-
ref: "Website",
|
|
14
|
-
default: null,
|
|
15
|
-
},
|
|
16
11
|
oldId: { type: String, default: "" },
|
|
17
12
|
webTagId: { type: Number, default: "" },
|
|
18
13
|
createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
@@ -13,11 +13,6 @@ const VariantLocationSchema = new Schema(
|
|
|
13
13
|
ref: "Workspace",
|
|
14
14
|
default: null,
|
|
15
15
|
},
|
|
16
|
-
websiteId: {
|
|
17
|
-
type: Schema.Types.ObjectId,
|
|
18
|
-
ref: "Website",
|
|
19
|
-
default: null,
|
|
20
|
-
},
|
|
21
16
|
productId: { type: Schema.Types.ObjectId, ref: "Product", default: null },
|
|
22
17
|
locationId: { type: Schema.Types.ObjectId, ref: "Location", default: null },
|
|
23
18
|
webVariantLocationId: { type: Number, default: null },
|
package/models.js
CHANGED
|
@@ -105,6 +105,7 @@ const WhatsappFlow = require("./models/WhatsappFlow");
|
|
|
105
105
|
const Workflow = require("./models/Workflow");
|
|
106
106
|
const Workspace = require("./models/Workspace");
|
|
107
107
|
const Shop = require("./models/Shop");
|
|
108
|
+
const Call = require("./models/Call");
|
|
108
109
|
|
|
109
110
|
module.exports = {
|
|
110
111
|
Activity,
|
|
@@ -214,4 +215,5 @@ module.exports = {
|
|
|
214
215
|
Workflow,
|
|
215
216
|
Workspace,
|
|
216
217
|
Shop,
|
|
218
|
+
Call,
|
|
217
219
|
};
|