shuttlepro-shared 1.4.3 → 1.4.5
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 +37 -0
- package/common/repositories/index.js +0 -3
- package/config/socket.js +30 -249
- package/models/Attribute.js +5 -0
- package/models/Category.js +5 -0
- package/models/Checkpoint.js +5 -0
- package/models/Customer.js +5 -0
- package/models/Location.js +5 -0
- package/models/Order.js +6 -0
- package/models/OrderPdf.js +5 -0
- package/models/OrderProduct.js +5 -0
- package/models/Product.js +5 -0
- package/models/ProductAttachment.js +5 -0
- package/models/ProductAttribute.js +5 -0
- package/models/ProductCategory.js +5 -0
- package/models/ProductTag.js +5 -0
- package/models/ProductVariant.js +5 -0
- package/models/Tag.js +5 -0
- package/models/VariantLocation.js +5 -0
- package/models.js +0 -2
- package/package.json +1 -1
- package/common/repositories/call.repository.js +0 -529
- package/models/Call.js +0 -196
package/models/Call.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
const mongoose = require("mongoose");
|
|
2
|
-
const { Schema } = mongoose;
|
|
3
|
-
|
|
4
|
-
const callSchema = new mongoose.Schema(
|
|
5
|
-
{
|
|
6
|
-
callId: {
|
|
7
|
-
type: String,
|
|
8
|
-
required: true,
|
|
9
|
-
unique: true,
|
|
10
|
-
index: true,
|
|
11
|
-
},
|
|
12
|
-
callerName: {
|
|
13
|
-
type: String,
|
|
14
|
-
required: true,
|
|
15
|
-
},
|
|
16
|
-
callerNumber: {
|
|
17
|
-
type: String,
|
|
18
|
-
required: true,
|
|
19
|
-
index: true,
|
|
20
|
-
},
|
|
21
|
-
status: {
|
|
22
|
-
type: String,
|
|
23
|
-
enum: ["pending", "hold", "active", "ended", "disconnected"],
|
|
24
|
-
default: "pending",
|
|
25
|
-
index: true,
|
|
26
|
-
},
|
|
27
|
-
queuePosition: {
|
|
28
|
-
type: Number,
|
|
29
|
-
default: 0,
|
|
30
|
-
},
|
|
31
|
-
isOnHold: {
|
|
32
|
-
type: Boolean,
|
|
33
|
-
default: false,
|
|
34
|
-
index: true,
|
|
35
|
-
},
|
|
36
|
-
autoAccepted: {
|
|
37
|
-
type: Boolean,
|
|
38
|
-
default: false,
|
|
39
|
-
},
|
|
40
|
-
isHoldConnection: {
|
|
41
|
-
type: Boolean,
|
|
42
|
-
default: false,
|
|
43
|
-
},
|
|
44
|
-
agentId: {
|
|
45
|
-
type: String,
|
|
46
|
-
default: null,
|
|
47
|
-
index: true,
|
|
48
|
-
},
|
|
49
|
-
startTime: {
|
|
50
|
-
type: Date,
|
|
51
|
-
default: null,
|
|
52
|
-
},
|
|
53
|
-
endTime: {
|
|
54
|
-
type: Date,
|
|
55
|
-
default: null,
|
|
56
|
-
},
|
|
57
|
-
duration: {
|
|
58
|
-
type: Number,
|
|
59
|
-
default: 0,
|
|
60
|
-
},
|
|
61
|
-
whatsappSdp: {
|
|
62
|
-
type: String,
|
|
63
|
-
default: null,
|
|
64
|
-
},
|
|
65
|
-
browserSdp: {
|
|
66
|
-
type: String,
|
|
67
|
-
default: null,
|
|
68
|
-
},
|
|
69
|
-
connectionMetadata: {
|
|
70
|
-
browserConnectionState: {
|
|
71
|
-
type: String,
|
|
72
|
-
default: "new",
|
|
73
|
-
},
|
|
74
|
-
whatsappConnectionState: {
|
|
75
|
-
type: String,
|
|
76
|
-
default: "new",
|
|
77
|
-
},
|
|
78
|
-
lastHeartbeat: {
|
|
79
|
-
type: Date,
|
|
80
|
-
default: Date.now,
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
type: { type: String, default: "inbound" },
|
|
84
|
-
callHistory: [
|
|
85
|
-
{
|
|
86
|
-
action: {
|
|
87
|
-
type: String,
|
|
88
|
-
enum: [
|
|
89
|
-
"created",
|
|
90
|
-
"answered",
|
|
91
|
-
"held",
|
|
92
|
-
"unheld",
|
|
93
|
-
"transferred",
|
|
94
|
-
"ended",
|
|
95
|
-
"disconnected",
|
|
96
|
-
"reconnected",
|
|
97
|
-
],
|
|
98
|
-
},
|
|
99
|
-
timestamp: {
|
|
100
|
-
type: Date,
|
|
101
|
-
default: Date.now,
|
|
102
|
-
},
|
|
103
|
-
agentId: String,
|
|
104
|
-
details: String,
|
|
105
|
-
},
|
|
106
|
-
],
|
|
107
|
-
platformTimestamp: {
|
|
108
|
-
type: String,
|
|
109
|
-
default: "",
|
|
110
|
-
},
|
|
111
|
-
receiver: {
|
|
112
|
-
type: String,
|
|
113
|
-
default: "",
|
|
114
|
-
},
|
|
115
|
-
platformId: {
|
|
116
|
-
type: Schema.Types.ObjectId,
|
|
117
|
-
ref: "Integration",
|
|
118
|
-
default: null,
|
|
119
|
-
},
|
|
120
|
-
workspaceId: { type: Schema.Types.ObjectId, ref: "Workspace" },
|
|
121
|
-
profileId: { type: Schema.Types.ObjectId, ref: "Profile" },
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
timestamps: true,
|
|
125
|
-
collection: "calls",
|
|
126
|
-
}
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
// Indexes for performance
|
|
130
|
-
callSchema.index({ status: 1, createdAt: 1 });
|
|
131
|
-
callSchema.index({ agentId: 1, status: 1 });
|
|
132
|
-
callSchema.index({ callerNumber: 1, createdAt: -1 });
|
|
133
|
-
callSchema.index({ isOnHold: 1, status: 1 });
|
|
134
|
-
|
|
135
|
-
// Virtual for call duration calculation
|
|
136
|
-
callSchema.virtual("currentDuration").get(function () {
|
|
137
|
-
if (this.startTime) {
|
|
138
|
-
const endTime = this.endTime || new Date();
|
|
139
|
-
return Math.floor((endTime - this.startTime) / 1000);
|
|
140
|
-
}
|
|
141
|
-
return 0;
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
// Methods
|
|
145
|
-
callSchema.methods.addToHistory = function (
|
|
146
|
-
action,
|
|
147
|
-
agentId = null,
|
|
148
|
-
details = null
|
|
149
|
-
) {
|
|
150
|
-
this.callHistory.push({
|
|
151
|
-
action,
|
|
152
|
-
agentId,
|
|
153
|
-
details,
|
|
154
|
-
timestamp: new Date(),
|
|
155
|
-
});
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
callSchema.methods.updateHeartbeat = function () {
|
|
159
|
-
this.connectionMetadata.lastHeartbeat = new Date();
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
callSchema.methods.isStale = function (timeoutMinutes = 5) {
|
|
163
|
-
const timeout = timeoutMinutes * 60 * 1000; // Convert to milliseconds
|
|
164
|
-
return new Date() - this.connectionMetadata.lastHeartbeat > timeout;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
// Static methods
|
|
168
|
-
callSchema.statics.getActiveCallsForAgent = function (agentId) {
|
|
169
|
-
return this.find({
|
|
170
|
-
agentId,
|
|
171
|
-
status: { $in: ["active", "hold"] },
|
|
172
|
-
}).sort({ createdAt: 1 });
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
callSchema.statics.getHoldQueue = function () {
|
|
176
|
-
return this.find({
|
|
177
|
-
status: "hold",
|
|
178
|
-
agentId: null,
|
|
179
|
-
}).sort({ createdAt: 1 });
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
callSchema.statics.getPendingCalls = function () {
|
|
183
|
-
return this.find({
|
|
184
|
-
status: "pending",
|
|
185
|
-
}).sort({ createdAt: 1 });
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
callSchema.statics.getStaleConnections = function (timeoutMinutes = 5) {
|
|
189
|
-
const timeout = new Date(Date.now() - timeoutMinutes * 60 * 1000);
|
|
190
|
-
return this.find({
|
|
191
|
-
status: { $in: ["active", "hold", "pending"] },
|
|
192
|
-
"connectionMetadata.lastHeartbeat": { $lt: timeout },
|
|
193
|
-
});
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
module.exports = mongoose.model("Call", callSchema);
|