shuttlepro-shared 1.4.13 → 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.
@@ -35,6 +35,31 @@ class CallRepository {
35
35
  }
36
36
  }
37
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
+
38
63
  async updateCall(callId, updateData) {
39
64
  try {
40
65
  const allowedFields = [
@@ -70,6 +95,7 @@ class CallRepository {
70
95
  agentId: updateData.agentId || null,
71
96
  details:
72
97
  updateData.reason || `Status changed to ${updateData.status}`,
98
+ direction: "Agent Initiated",
73
99
  },
74
100
  };
75
101
  }
@@ -165,46 +191,27 @@ class CallRepository {
165
191
  }
166
192
  }
167
193
 
168
- async endCall(callId, agentId = null, updateObj = {}) {
169
- try {
170
- return await Call.findOneAndUpdate(
171
- { callId },
172
- {
173
- $set: {
174
- status: "ended",
175
- endTime: new Date(),
176
- "connectionMetadata.lastHeartbeat": new Date(),
177
- ...updateObj,
178
- },
179
- $push: {
180
- callHistory: {
181
- timestamp: new Date(),
182
- action: "ended",
183
- agentId,
184
- details: "Call ended",
185
- },
186
- },
187
- },
188
- { new: true }
189
- );
190
- } catch (error) {
191
- console.error(`❌ Failed to end call ${callId}:`, error);
192
- return null;
193
- }
194
- }
195
-
196
194
  /* ----------------- Query Helpers ----------------- */
197
195
 
198
196
  async getCallsByWorkspace(workspaceId, filters = {}) {
199
- return Call.find({ workspaceId, ...filters }).sort({ createdAt: -1 });
197
+ return Call.find({ workspaceId, ...filters })
198
+ .sort({ createdAt: -1 })
199
+ .lean()
200
+ .exec();
200
201
  }
201
202
 
202
203
  async getCallsByAgent(agentId, filters = {}) {
203
- return Call.find({ agentId, ...filters }).sort({ createdAt: -1 });
204
+ return Call.find({ agentId, ...filters })
205
+ .sort({ createdAt: -1 })
206
+ .lean()
207
+ .exec();
204
208
  }
205
209
 
206
210
  async getCallsByReceiver(receiver, filters = {}) {
207
- return Call.find({ receiver, ...filters }).sort({ createdAt: -1 });
211
+ return Call.find({ receiver, ...filters })
212
+ .sort({ createdAt: -1 })
213
+ .lean()
214
+ .exec();
208
215
  }
209
216
 
210
217
  async getActiveCalls(workspaceId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shuttlepro-shared",
3
- "version": "1.4.13",
3
+ "version": "1.4.14",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {