@peopl-health/nexus 3.5.0 → 3.5.1
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.
|
@@ -78,21 +78,33 @@ const getConversationMessagesController = async (req, res) => {
|
|
|
78
78
|
error: 'Phone number is required'
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
-
|
|
82
|
-
const limit = parseInt(req.query.limit) || 50;
|
|
81
|
+
|
|
83
82
|
const { before } = req.query;
|
|
84
|
-
|
|
83
|
+
const limit = parseInt(req.query.limit) || 50;
|
|
84
|
+
const page = parseInt(req.query.page) || 1;
|
|
85
|
+
const skip = (page - 1) * limit;
|
|
86
|
+
|
|
85
87
|
const query = { numero: phoneNumber, group_id: null };
|
|
86
88
|
if (before) {
|
|
87
89
|
query.createdAt = { $lt: new Date(before) };
|
|
88
90
|
}
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
91
|
+
|
|
92
|
+
const total = await Message.countDocuments(query);
|
|
93
|
+
const messages = await Message.find(query).sort({ createdAt: -1 }).skip(skip).limit(limit).lean();
|
|
94
|
+
const totalPages = Math.ceil(total / limit);
|
|
95
|
+
|
|
92
96
|
res.status(200).json({
|
|
93
97
|
success: true,
|
|
94
98
|
phoneNumber,
|
|
95
|
-
messages: messages.reverse()
|
|
99
|
+
messages: messages.reverse(),
|
|
100
|
+
pagination: {
|
|
101
|
+
page,
|
|
102
|
+
limit,
|
|
103
|
+
total,
|
|
104
|
+
totalPages,
|
|
105
|
+
hasNext: page < totalPages,
|
|
106
|
+
hasPrev: page > 1
|
|
107
|
+
}
|
|
96
108
|
});
|
|
97
109
|
} catch (error) {
|
|
98
110
|
logger.error('Error fetching conversation messages:', { error: error.message, phoneNumber: req.params?.phoneNumber });
|