@peopl-health/nexus 4.3.2 → 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.message });
122
+ res.status(500).json({ success: false, error: 'Internal server error' });
110
123
  }
111
124
  };
112
125
 
@@ -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
- inmediatePatch: { type: String, default: null },
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 };
@@ -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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "4.3.2",
3
+ "version": "4.3.3",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",