@peopl-health/nexus 4.3.1 → 4.3.3
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.
|
@@ -4,7 +4,7 @@ const runtimeConfig = require('../config/runtimeConfig');
|
|
|
4
4
|
const { logger } = require('../utils/logger');
|
|
5
5
|
|
|
6
6
|
const { Message } = require('../models/messageModel');
|
|
7
|
-
const { getBug, VALID_SEVERITIES } = require('../models/bugModel');
|
|
7
|
+
const { getBug, VALID_SEVERITIES, UPDATABLE_FIELDS } = require('../models/bugModel');
|
|
8
8
|
|
|
9
9
|
const { addRecord, getRecordByFilter } = require('../services/airtableService');
|
|
10
10
|
|
|
@@ -99,14 +99,27 @@ const updateBugController = async (req, res) => {
|
|
|
99
99
|
return res.status(400).json({ success: false, error: 'No fields provided for update' });
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
const disallowed = Object.keys(fields).filter(k => !UPDATABLE_FIELDS.includes(k));
|
|
103
|
+
if (disallowed.length > 0) {
|
|
104
|
+
return res.status(400).json({ success: false, error: `Fields not allowed for update: ${disallowed.join(', ')}` });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (fields.severity != null && !VALID_SEVERITIES.includes(fields.severity)) {
|
|
108
|
+
return res.status(400).json({ success: false, error: `Severity must be one of: ${VALID_SEVERITIES.join(', ')}` });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (fields.project !== undefined && (typeof fields.project !== 'object' || Array.isArray(fields.project))) {
|
|
112
|
+
return res.status(400).json({ success: false, error: 'project must be an object' });
|
|
113
|
+
}
|
|
114
|
+
|
|
102
115
|
const Bug = getBug();
|
|
103
|
-
const updatedBug = await Bug.findOneAndUpdate({ recordId }, fields, { new: true });
|
|
116
|
+
const updatedBug = await Bug.findOneAndUpdate({ recordId }, { $set: fields }, { new: true, runValidators: true });
|
|
104
117
|
if (!updatedBug) return res.status(404).json({ success: false, error: 'Bug not found' });
|
|
105
118
|
|
|
106
119
|
res.status(200).json({ success: true, bug: updatedBug });
|
|
107
120
|
} catch (error) {
|
|
108
121
|
logger.error('Error updating bug report:', { error: error.message, recordId: req.params?.recordId });
|
|
109
|
-
res.status(500).json({ success: false, error: error
|
|
122
|
+
res.status(500).json({ success: false, error: 'Internal server error' });
|
|
110
123
|
}
|
|
111
124
|
};
|
|
112
125
|
|
|
@@ -57,10 +57,10 @@ const _sendBulkMessages = async (payloads, res, logMessage) => {
|
|
|
57
57
|
|
|
58
58
|
const sendMessageController = async (req, res) => {
|
|
59
59
|
if (!_validateMessagingDeps(res)) return;
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
const {
|
|
62
62
|
fileUrl, message, fileType, code,
|
|
63
|
-
sendTime
|
|
63
|
+
sendTime,
|
|
64
64
|
timeZone = 'Etc/GMT',
|
|
65
65
|
hidePreview = false,
|
|
66
66
|
contentSid = null,
|
|
@@ -71,12 +71,30 @@ const sendMessageController = async (req, res) => {
|
|
|
71
71
|
|
|
72
72
|
try {
|
|
73
73
|
const finalVariables = contentSid ? await ensureFlowTokenInVariables(contentSid, variables) : variables;
|
|
74
|
+
const formattedCode = ensureWhatsAppFormat(code);
|
|
75
|
+
|
|
76
|
+
if (!sendTime) {
|
|
77
|
+
const result = await sendMessage({
|
|
78
|
+
fileUrl, body: message, fileType, contentSid, hidePreview,
|
|
79
|
+
variables: finalVariables, code: formattedCode,
|
|
80
|
+
frontendId, triggeredBy
|
|
81
|
+
});
|
|
82
|
+
return res.status(200).json({
|
|
83
|
+
success: result?.success ?? true,
|
|
84
|
+
messageId: _pickMessageId(result, null),
|
|
85
|
+
status: result?.status || null,
|
|
86
|
+
...(result?.preemptive && {
|
|
87
|
+
preemptive: true,
|
|
88
|
+
note: 'Recipient outside 24h window; template approval in progress, delivery not guaranteed within the next 15 min'
|
|
89
|
+
})
|
|
90
|
+
});
|
|
91
|
+
}
|
|
74
92
|
|
|
75
93
|
const payload = {
|
|
76
94
|
fileUrl, message, fileType, contentSid, hidePreview, variables: finalVariables,
|
|
77
95
|
timeZone: timeZone || null,
|
|
78
|
-
sendTime:
|
|
79
|
-
code:
|
|
96
|
+
sendTime: moment.tz(sendTime, timeZone) + 2500,
|
|
97
|
+
code: formattedCode,
|
|
80
98
|
frontendId,
|
|
81
99
|
triggeredBy
|
|
82
100
|
};
|
package/lib/models/bugModel.js
CHANGED
|
@@ -4,6 +4,7 @@ const { getDb, getModelDatabase } = require('../config/mongoConfig');
|
|
|
4
4
|
const { logger } = require('../utils/logger');
|
|
5
5
|
|
|
6
6
|
const VALID_SEVERITIES = ['low', 'medium', 'high', 'critical'];
|
|
7
|
+
const UPDATABLE_FIELDS = ['status', 'repository', 'issue', 'assignees', 'pullRequests', 'resolution', 'immediatePatch', 'severity', 'server', 'bugType', 'project'];
|
|
7
8
|
|
|
8
9
|
const bugSchema = new mongoose.Schema({
|
|
9
10
|
reporter: { type: String, required: true, index: true },
|
|
@@ -19,7 +20,7 @@ const bugSchema = new mongoose.Schema({
|
|
|
19
20
|
assignees: [{ type: String, default: null }],
|
|
20
21
|
pullRequests: [{ type: String, default: null }],
|
|
21
22
|
resolution: { type: String, default: null },
|
|
22
|
-
|
|
23
|
+
immediatePatch: { type: String, default: null },
|
|
23
24
|
recordId: { type: String, default: null },
|
|
24
25
|
project: {
|
|
25
26
|
projectId: { type: String, default: null },
|
|
@@ -34,4 +35,4 @@ const getBug = () => {
|
|
|
34
35
|
return db.models.Bug || db.model('Bug', bugSchema);
|
|
35
36
|
};
|
|
36
37
|
|
|
37
|
-
module.exports = { getBug, bugSchema, VALID_SEVERITIES };
|
|
38
|
+
module.exports = { getBug, bugSchema, VALID_SEVERITIES, UPDATABLE_FIELDS };
|
package/lib/routes/index.js
CHANGED
|
@@ -147,6 +147,7 @@ const builtInControllers = {
|
|
|
147
147
|
markMessagesAsReadController: conversationController.markMessagesAsReadController,
|
|
148
148
|
searchMessagesByNumberController: conversationController.searchMessagesByNumberController,
|
|
149
149
|
reportBugController: bugReportController.reportBugController,
|
|
150
|
+
updateBugController: bugReportController.updateBugController,
|
|
150
151
|
getBugByWhatsappIdController: bugReportController.getBugByWhatsappIdController,
|
|
151
152
|
caseDocumentationController: caseDocumentationController.caseDocumentationController,
|
|
152
153
|
|