Files
makemd/server/src/api/controllers/ConfigController.ts
wurenzhi 2748456d8a refactor(services): 重构服务文件结构,将服务按功能分类到不同目录
- 将服务文件按功能分类到core、ai、analytics、security等目录
- 修复logger导入路径问题,统一使用相对路径
- 更新相关文件的导入路径引用
- 添加新的批量操作组件导出文件
- 修复dashboard页面中的类型错误
- 添加dotenv依赖到package.json
2026-03-25 13:46:26 +08:00

60 lines
1.9 KiB
TypeScript

import { Request, Response } from 'express';
import { ConfigService } from '../../services/utils/ConfigService';
import { AuditService } from '../../services/utils/AuditService';
export class ConfigController {
static async getAll(req: Request, res: Response) {
try {
const configs = await ConfigService.getAllConfigs();
res.json({ success: true, data: configs });
} catch (err: any) {
res.status(500).json({ success: false, error: err.message });
}
}
static async update(req: Request, res: Response) {
const key = String(req.params.key);
const { isEnabled, value } = req.body;
const { tenantId, shopId, taskId, traceId, userId } = (req as any).traceContext;
try {
const beforeSnapshot = await ConfigService.getConfig(key);
if (!beforeSnapshot) return res.status(404).json({ success: false, error: 'Config not found' });
await ConfigService.updateConfig(key, { isEnabled, value });
const afterSnapshot = await ConfigService.getConfig(key);
await AuditService.logDiff({
tenantId,
shopId,
taskId,
traceId,
userId,
module: 'CONFIG',
action: 'UPDATE_CONFIG',
resourceType: 'config',
resourceId: key,
beforeSnapshot,
afterSnapshot,
source: 'console'
});
res.json({ success: true });
} catch (err: any) {
res.status(500).json({ success: false, error: err.message });
}
}
static async getByKey(req: Request, res: Response) {
const key = String(req.params.key);
try {
const config = await ConfigService.getConfig(key);
if (!config) return res.status(404).json({ success: false, error: 'Config not found' });
res.json({ success: true, data: config });
} catch (err: any) {
res.status(500).json({ success: false, error: err.message });
}
}
}