@peopl-health/nexus 3.3.1-fix → 3.3.2
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.
|
@@ -5,7 +5,7 @@ const { addRecord, getRecordByFilter } = require('../services/airtableService');
|
|
|
5
5
|
const { Logging_ID } = require('../config/airtableConfig');
|
|
6
6
|
const { logger } = require('../utils/logger');
|
|
7
7
|
|
|
8
|
-
async function logInteractionToAirtable(messageIds, whatsapp_id, voter_username, description) {
|
|
8
|
+
async function logInteractionToAirtable(messageIds, whatsapp_id, voter_username, description, type, medical_note) {
|
|
9
9
|
try {
|
|
10
10
|
const messageObjects = await Message.find({ _id: { $in: messageIds } }).sort({ createdAt: -1 });
|
|
11
11
|
|
|
@@ -29,7 +29,9 @@ async function logInteractionToAirtable(messageIds, whatsapp_id, voter_username,
|
|
|
29
29
|
patient_id: patientId ? [patientId] : undefined,
|
|
30
30
|
reporter: voter_username,
|
|
31
31
|
conversation,
|
|
32
|
-
description
|
|
32
|
+
description,
|
|
33
|
+
type: type && type.length ? type : undefined,
|
|
34
|
+
medical_note: medical_note || undefined
|
|
33
35
|
};
|
|
34
36
|
|
|
35
37
|
await addRecord(Logging_ID, 'interactions', airtableData);
|
|
@@ -41,7 +43,7 @@ async function logInteractionToAirtable(messageIds, whatsapp_id, voter_username,
|
|
|
41
43
|
|
|
42
44
|
const addInteractionController = async (req, res) => {
|
|
43
45
|
try {
|
|
44
|
-
const { messages, whatsapp_id, voter_username, quality, description } = req.body;
|
|
46
|
+
const { messages, whatsapp_id, voter_username, quality, description, type, medical_note } = req.body;
|
|
45
47
|
if (!messages || !Array.isArray(messages) || messages.length === 0) {
|
|
46
48
|
return res.status(400).json({ success: false, error: 'Messages array is required and must not be empty' });
|
|
47
49
|
}
|
|
@@ -50,9 +52,11 @@ const addInteractionController = async (req, res) => {
|
|
|
50
52
|
if (!quality || !INTERACTION_QUALITY_VALUES.includes(quality)) {
|
|
51
53
|
return res.status(400).json({ success: false, error: `Quality must be one of: ${INTERACTION_QUALITY_VALUES.join(', ')}` });
|
|
52
54
|
}
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
const typeArray = Array.isArray(type) ? type : type ? [type] : undefined;
|
|
56
|
+
const Interaction = getInteraction();
|
|
57
|
+
const interaction = await Interaction.create({ messages, whatsapp_id, voter_username, quality, description, type: typeArray, medical_note });
|
|
58
|
+
|
|
59
|
+
logInteractionToAirtable(messages, whatsapp_id, voter_username, description, typeArray, medical_note).catch(err =>
|
|
56
60
|
logger.error('Background Airtable logging failed:', err)
|
|
57
61
|
);
|
|
58
62
|
|
|
@@ -66,7 +70,8 @@ const addInteractionController = async (req, res) => {
|
|
|
66
70
|
const getInteractionsByWhatsappIdController = async (req, res) => {
|
|
67
71
|
try {
|
|
68
72
|
const { whatsapp_id } = req.params;
|
|
69
|
-
const
|
|
73
|
+
const Interaction = getInteraction();
|
|
74
|
+
const interactions = await Interaction.find({ whatsapp_id }).populate('messages').sort({ createdAt: -1 });
|
|
70
75
|
res.status(200).json({ success: true, whatsappId: whatsapp_id, count: interactions.length, interactions });
|
|
71
76
|
} catch (error) {
|
|
72
77
|
logger.error('Error fetching interactions:', error);
|
|
@@ -13,6 +13,8 @@ const interactionSchema = new mongoose.Schema({
|
|
|
13
13
|
required: true
|
|
14
14
|
},
|
|
15
15
|
description: { type: String, default: null },
|
|
16
|
+
medical_note: { type: String, default: null },
|
|
17
|
+
type: { type: [String], default: [] },
|
|
16
18
|
source: { type: String, default: () => process.env.USER_DB_MONGO }
|
|
17
19
|
}, { timestamps: true });
|
|
18
20
|
|