v1.13.4: Standardize all route responses to use response helpers
Convert ~160 raw res.json()/res.status().json() calls across 32+ files to use centralized helpers from src/utils/responses.js (ok, errorResponse, successMessage, notFound, validationError, forbidden, unauthorized, conflict). No behavior changes — response shapes are identical. Future schema changes (e.g., requestId envelope) only need to update one module. Fix error vs errorResponse signature mismatch in routes/health.js CA cert endpoint where error(res, message, statusCode) was being called with errorResponse(res, statusCode, message, extras) argument order. Files changed: middleware.js, csrf-protection.js, error-handler.js, license-manager.js, src/app.js, and 27 route files. Test suite: 755 pass / 4 pre-existing failures (services credential tests).
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const express = require('express');
|
||||
const { ok } = require('../src/utils/responses');
|
||||
|
||||
/**
|
||||
* Workflows routes factory
|
||||
@@ -19,21 +20,21 @@ module.exports = function({ workflowEngine, licenseManager, asyncHandler }) {
|
||||
// List all bundled workflows
|
||||
router.get('/workflows', asyncHandler(async (req, res) => {
|
||||
const workflows = workflowEngine.listWorkflows();
|
||||
res.json({ success: true, workflows });
|
||||
ok(res, { workflows });
|
||||
}, 'workflows-list'));
|
||||
|
||||
// Enable a workflow
|
||||
router.post('/workflows/:workflowId/enable', asyncHandler(async (req, res) => {
|
||||
const { workflowId } = req.params;
|
||||
const result = workflowEngine.setWorkflowEnabled(workflowId, true);
|
||||
res.json({ success: true, ...result });
|
||||
ok(res, result);
|
||||
}, 'workflows-enable'));
|
||||
|
||||
// Disable a workflow
|
||||
router.post('/workflows/:workflowId/disable', asyncHandler(async (req, res) => {
|
||||
const { workflowId } = req.params;
|
||||
const result = workflowEngine.setWorkflowEnabled(workflowId, false);
|
||||
res.json({ success: true, ...result });
|
||||
ok(res, result);
|
||||
}, 'workflows-disable'));
|
||||
|
||||
// Manually trigger a workflow
|
||||
@@ -43,7 +44,7 @@ module.exports = function({ workflowEngine, licenseManager, asyncHandler }) {
|
||||
triggerData.trigger = 'manual';
|
||||
|
||||
const result = await workflowEngine.executeWorkflow(workflowId, triggerData);
|
||||
res.json({ success: true, result });
|
||||
ok(res, { result });
|
||||
}, 'workflows-run'));
|
||||
|
||||
// Get execution history for a workflow
|
||||
@@ -51,14 +52,14 @@ module.exports = function({ workflowEngine, licenseManager, asyncHandler }) {
|
||||
const { workflowId } = req.params;
|
||||
const limit = parseInt(req.query.limit) || 50;
|
||||
const history = workflowEngine.getHistory(workflowId, limit);
|
||||
res.json({ success: true, history });
|
||||
ok(res, { history });
|
||||
}, 'workflows-history'));
|
||||
|
||||
// Get all workflow execution history
|
||||
router.get('/workflows/history', asyncHandler(async (req, res) => {
|
||||
const limit = parseInt(req.query.limit) || 100;
|
||||
const history = workflowEngine.getHistory(null, limit);
|
||||
res.json({ success: true, history });
|
||||
ok(res, { history });
|
||||
}, 'workflows-all-history'));
|
||||
|
||||
return router;
|
||||
|
||||
Reference in New Issue
Block a user