import { Request, Response } from "express"; import { ApiResponse } from "../core/ApiResponse"; interface ApiResponseData { data?: T; message?: string; } export abstract class BaseController { protected async handleRequest( req: Request, res: Response, action: () => Promise | void> ): Promise { try { const result = await action(); if (result) { res.json(ApiResponse.success(result.data, result.message)); } } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : "未知错误"; res.status(200).json(ApiResponse.error(errorMessage)); } } }