whistle.mock-plugins 1.1.1-dev.13 → 1.1.1-dev.15

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.
@@ -183,6 +183,7 @@ module.exports = function(req, res) {
183
183
  interfacesData.interfaces[index] = {
184
184
  ...interfacesData.interfaces[index],
185
185
  name: interfaceData.name,
186
+ group: interfaceData.group !== undefined ? interfaceData.group : interfacesData.interfaces[index].group || '', // 添加分组字段
186
187
  urlPattern: interfaceData.urlPattern,
187
188
  proxyType: interfaceData.proxyType,
188
189
  responseContent: interfaceData.responseContent,
@@ -217,6 +218,7 @@ module.exports = function(req, res) {
217
218
  id: Date.now().toString(),
218
219
  featureId: interfaceData.featureId,
219
220
  name: interfaceData.name,
221
+ group: interfaceData.group || '', // 添加分组字段
220
222
  urlPattern: interfaceData.urlPattern,
221
223
  proxyType: interfaceData.proxyType || 'response',
222
224
  responseContent: interfaceData.responseContent || '',
@@ -235,6 +237,7 @@ module.exports = function(req, res) {
235
237
 
236
238
  console.log('创建新接口,包含多响应数据:', {
237
239
  name: newInterface.name,
240
+ group: newInterface.group, // 添加分组日志
238
241
  responsesCount: newInterface.responses.length,
239
242
  activeResponseId: newInterface.activeResponseId
240
243
  });
@@ -343,6 +346,7 @@ module.exports = function(req, res) {
343
346
  const updatedInterface = {
344
347
  ...interfacesData.interfaces[index],
345
348
  name: interfaceData.name || interfacesData.interfaces[index].name,
349
+ group: interfaceData.group !== undefined ? interfaceData.group : interfacesData.interfaces[index].group || '', // 添加分组字段
346
350
  urlPattern: interfaceData.urlPattern || interfacesData.interfaces[index].urlPattern,
347
351
  proxyType: interfaceData.proxyType || interfacesData.interfaces[index].proxyType,
348
352
  responseContent: interfaceData.responseContent !== undefined ? interfaceData.responseContent : interfacesData.interfaces[index].responseContent,
@@ -362,6 +366,7 @@ module.exports = function(req, res) {
362
366
 
363
367
  console.log('PUT更新接口,包含多响应数据:', {
364
368
  name: updatedInterface.name,
369
+ group: updatedInterface.group, // 添加分组日志
365
370
  responsesCount: updatedInterface.responses.length,
366
371
  activeResponseId: updatedInterface.activeResponseId
367
372
  });
@@ -378,17 +383,9 @@ module.exports = function(req, res) {
378
383
 
379
384
  // 处理 PATCH 请求 - 部分更新接口(如启用/禁用状态)
380
385
  if (req.method === 'PATCH') {
381
- const { id } = req.query;
386
+ const { id, active } = req.query;
382
387
  const patchData = req.body;
383
388
 
384
- if (!id) {
385
- return res.status(400).json({
386
- code: 400,
387
- message: '接口ID不能为空',
388
- data: null
389
- });
390
- }
391
-
392
389
  // 读取接口数据
393
390
  let interfacesData;
394
391
  try {
@@ -405,6 +402,70 @@ module.exports = function(req, res) {
405
402
  });
406
403
  }
407
404
 
405
+ // 批量更新接口状态
406
+ if (active !== undefined) {
407
+ const { featureId, group } = patchData;
408
+
409
+ if (!featureId) {
410
+ return res.status(400).json({
411
+ code: 400,
412
+ message: '功能ID不能为空',
413
+ data: null
414
+ });
415
+ }
416
+
417
+ // 根据分组筛选要更新的接口
418
+ let updatedCount = 0;
419
+ interfacesData.interfaces = interfacesData.interfaces.map(item => {
420
+ // 只更新指定功能模块下的接口
421
+ if (item.featureId !== featureId) {
422
+ return item;
423
+ }
424
+
425
+ // 如果指定了分组,只更新该分组下的接口
426
+ if (group && item.group !== group) {
427
+ return item;
428
+ }
429
+
430
+ // 更新接口状态
431
+ const isActive = active === 'true';
432
+ if (item.active !== isActive) {
433
+ updatedCount++;
434
+ return {
435
+ ...item,
436
+ active: isActive,
437
+ updatedAt: new Date().toISOString()
438
+ };
439
+ }
440
+
441
+ return item;
442
+ });
443
+
444
+ // 保存更新后的接口列表
445
+ fs.writeJsonSync(interfacesFile, interfacesData, { spaces: 2 });
446
+
447
+ console.log(`批量${active === 'true' ? '启用' : '禁用'}接口:`, {
448
+ featureId,
449
+ group,
450
+ updatedCount
451
+ });
452
+
453
+ return res.json({
454
+ code: 0,
455
+ message: `成功${active === 'true' ? '启用' : '禁用'} ${updatedCount} 个接口`,
456
+ data: { updatedCount }
457
+ });
458
+ }
459
+
460
+ // 单个接口更新
461
+ if (!id) {
462
+ return res.status(400).json({
463
+ code: 400,
464
+ message: '接口ID不能为空',
465
+ data: null
466
+ });
467
+ }
468
+
408
469
  // 查找接口
409
470
  const index = interfacesData.interfaces.findIndex(item => item.id === id);
410
471