refactor(routes): Phase 3.6-10 - standardize 5 utility routes
- credentials.js (2 deps: credentialManager, asyncHandler) - backups.js (2 deps: backupManager, asyncHandler) - license.js (2 deps: licenseManager, asyncHandler) - errorlogs.js (3 deps: ERROR_LOG_FILE, auditLogger, asyncHandler) - themes.js (0 deps! Standalone route) Total: 9 routes refactored so far
This commit is contained in:
@@ -1,37 +1,45 @@
|
||||
const express = require('express');
|
||||
const { success } = require('../response-helpers');
|
||||
|
||||
module.exports = function(ctx) {
|
||||
/**
|
||||
* Backups routes factory
|
||||
* @param {Object} deps - Explicit dependencies
|
||||
* @param {Object} deps.backupManager - Backup management module
|
||||
* @param {Function} deps.asyncHandler - Async route handler wrapper
|
||||
* @returns {express.Router}
|
||||
*/
|
||||
module.exports = function({ backupManager, asyncHandler }) {
|
||||
const router = express.Router();
|
||||
|
||||
// Get backup configuration
|
||||
router.get('/backups/config', ctx.asyncHandler(async (req, res) => {
|
||||
const config = ctx.backupManager.getConfig();
|
||||
res.json({ success: true, config });
|
||||
router.get('/backups/config', asyncHandler(async (req, res) => {
|
||||
const config = backupManager.getConfig();
|
||||
success(res, { config });
|
||||
}, 'backups-config-get'));
|
||||
|
||||
// Update backup configuration
|
||||
router.post('/backups/config', ctx.asyncHandler(async (req, res) => {
|
||||
ctx.backupManager.updateConfig(req.body);
|
||||
res.json({ success: true, message: 'Backup configuration updated' });
|
||||
router.post('/backups/config', asyncHandler(async (req, res) => {
|
||||
backupManager.updateConfig(req.body);
|
||||
success(res, { message: 'Backup configuration updated' });
|
||||
}, 'backups-config-update'));
|
||||
|
||||
// Execute manual backup
|
||||
router.post('/backups/execute', ctx.asyncHandler(async (req, res) => {
|
||||
const backup = await ctx.backupManager.executeBackup('manual', req.body);
|
||||
res.json({ success: true, backup });
|
||||
router.post('/backups/execute', asyncHandler(async (req, res) => {
|
||||
const backup = await backupManager.executeBackup('manual', req.body);
|
||||
success(res, { backup });
|
||||
}, 'backups-execute'));
|
||||
|
||||
// Get backup history
|
||||
router.get('/backups/history', ctx.asyncHandler(async (req, res) => {
|
||||
router.get('/backups/history', asyncHandler(async (req, res) => {
|
||||
const limit = parseInt(req.query.limit) || 50;
|
||||
const history = ctx.backupManager.getHistory(limit);
|
||||
res.json({ success: true, history });
|
||||
const history = backupManager.getHistory(limit);
|
||||
success(res, { history });
|
||||
}, 'backups-history'));
|
||||
|
||||
// Restore from backup
|
||||
router.post('/backups/restore/:backupId', ctx.asyncHandler(async (req, res) => {
|
||||
const result = await ctx.backupManager.restoreBackup(req.params.backupId, req.body);
|
||||
res.json({ success: true, result });
|
||||
router.post('/backups/restore/:backupId', asyncHandler(async (req, res) => {
|
||||
const result = await backupManager.restoreBackup(req.params.backupId, req.body);
|
||||
success(res, { result });
|
||||
}, 'backups-restore'));
|
||||
|
||||
return router;
|
||||
|
||||
Reference in New Issue
Block a user