@peopl-health/nexus 4.2.6 → 4.2.8
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.
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
const moment = require('moment-timezone');
|
|
2
|
+
const mongoose = require('mongoose');
|
|
2
3
|
|
|
3
4
|
const { logger } = require('../utils/logger');
|
|
4
5
|
|
|
5
6
|
const { Message } = require('../models/messageModel.js');
|
|
6
7
|
const { ScheduledMessage } = require('../models/agendaMessageModel.js');
|
|
8
|
+
const { DeliveryAttempt } = require('../models/deliveryAttemptModel.js');
|
|
7
9
|
const FlowRouting = require('../models/flowRoutingModel.js');
|
|
8
10
|
|
|
9
11
|
const { ensureWhatsAppFormat } = require('../helpers/twilioHelper');
|
|
@@ -253,11 +255,29 @@ const checkMessageStatusController = async (req, res) => {
|
|
|
253
255
|
}
|
|
254
256
|
};
|
|
255
257
|
|
|
258
|
+
const getDeliveryAttemptsController = async (req, res) => {
|
|
259
|
+
const { id } = req.params;
|
|
260
|
+
if (!id || !mongoose.Types.ObjectId.isValid(id)) {
|
|
261
|
+
return res.status(400).json({ success: false, error: 'Valid message id is required' });
|
|
262
|
+
}
|
|
263
|
+
try {
|
|
264
|
+
const attempts = await DeliveryAttempt
|
|
265
|
+
.find({ messageId: id }, { raw: 0 })
|
|
266
|
+
.sort({ attemptedAt: 1 })
|
|
267
|
+
.lean();
|
|
268
|
+
return res.status(200).json({ success: true, attempts });
|
|
269
|
+
} catch (err) {
|
|
270
|
+
logger.error('Error fetching delivery attempts:', { messageId: id, error: err.message });
|
|
271
|
+
return res.status(500).json({ success: false, error: 'Failed to fetch delivery attempts' });
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
|
|
256
275
|
module.exports = {
|
|
257
276
|
sendMessageController,
|
|
258
277
|
sendBulkMessageController,
|
|
259
278
|
sendBulkMessageAirtableController,
|
|
260
279
|
getLastInteractionController,
|
|
261
280
|
checkScheduledMessageStatusController,
|
|
262
|
-
checkMessageStatusController
|
|
281
|
+
checkMessageStatusController,
|
|
282
|
+
getDeliveryAttemptsController
|
|
263
283
|
};
|
|
@@ -37,6 +37,18 @@ async function recordDeliveryAttempt({
|
|
|
37
37
|
completedAt: new Date()
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
+
if (status) {
|
|
41
|
+
await Message.updateOne(
|
|
42
|
+
{ _id: targetId },
|
|
43
|
+
{ $set: {
|
|
44
|
+
'statusInfo.status': status,
|
|
45
|
+
'statusInfo.updatedAt': new Date(),
|
|
46
|
+
...(errorCode != null && { 'statusInfo.errorCode': String(errorCode) }),
|
|
47
|
+
...(errorMessage && { 'statusInfo.errorMessage': errorMessage })
|
|
48
|
+
}}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
40
52
|
return attempt;
|
|
41
53
|
} catch (error) {
|
|
42
54
|
logger.error('[deliveryAttemptHelper] Failed to record delivery attempt', {
|
package/lib/routes/index.js
CHANGED
|
@@ -49,7 +49,8 @@ const messageRouteDefinitions = {
|
|
|
49
49
|
'POST /quality': 'addQualityVoteController',
|
|
50
50
|
'GET /quality/:message_id': 'getQualityVotesByMessageController',
|
|
51
51
|
'GET /quality/:message_id/voter/:voter_username': 'getQualityVoteByMessageAndVoterController',
|
|
52
|
-
'GET /quality/voter/:voter_username': 'getQualityVotesByVoterController'
|
|
52
|
+
'GET /quality/voter/:voter_username': 'getQualityVotesByVoterController',
|
|
53
|
+
'GET /:id/attempts': 'getDeliveryAttemptsController'
|
|
53
54
|
};
|
|
54
55
|
|
|
55
56
|
const patientRouteDefinitions = {
|
|
@@ -164,6 +165,7 @@ const builtInControllers = {
|
|
|
164
165
|
getLastInteractionController: messageController.getLastInteractionController,
|
|
165
166
|
checkScheduledMessageStatusController: messageController.checkScheduledMessageStatusController,
|
|
166
167
|
checkMessageStatusController: messageController.checkMessageStatusController,
|
|
168
|
+
getDeliveryAttemptsController: messageController.getDeliveryAttemptsController,
|
|
167
169
|
getMessageStatusController: messageStatusController.getMessageStatusController,
|
|
168
170
|
messageStatusCallbackController: messageStatusController.messageStatusCallbackController,
|
|
169
171
|
addQualityVoteController: qualityMessageController.addQualityVoteController,
|