diff --git a/application/src/api/index.ts b/application/src/api/index.ts index ab26202..40c730b 100644 --- a/application/src/api/index.ts +++ b/application/src/api/index.ts @@ -1,6 +1,7 @@ // API routes handler import realtime from './realtime'; +import settingsApi from './settings'; /** * Simple API router for client-side application @@ -16,6 +17,9 @@ const api = { if (path === '/api/realtime') { console.log("Routing to realtime handler"); return await realtime(body); + } else if (path === '/api/settings') { + console.log("Routing to settings handler"); + return await settingsApi(body); } // Return 404 for unknown routes diff --git a/application/src/api/settings/index.ts b/application/src/api/settings/index.ts new file mode 100644 index 0000000..c9d3cf7 --- /dev/null +++ b/application/src/api/settings/index.ts @@ -0,0 +1,71 @@ + +import { settingsService } from "@/services/settingsService"; + +const settingsApi = async (body: any) => { + try { + const { action, data } = body; + + switch (action) { + case 'getSettings': + const settings = await settingsService.getGeneralSettings(); + return { + status: 200, + json: { + success: true, + data: settings + } + }; + + case 'updateSettings': + if (!data.id) { + return { + status: 400, + json: { + success: false, + message: 'Settings ID is required' + } + }; + } + + const updatedSettings = await settingsService.updateGeneralSettings(data.id, data); + return { + status: 200, + json: { + success: true, + data: updatedSettings + } + }; + + case 'testEmailConnection': + // This would typically connect to the SMTP server to test the connection + // For now, we'll just simulate a successful connection + return { + status: 200, + json: { + success: true, + message: 'Connection successful' + } + }; + + default: + return { + status: 400, + json: { + success: false, + message: 'Invalid action' + } + }; + } + } catch (error) { + console.error('Error in settings API:', error); + return { + status: 500, + json: { + success: false, + message: 'Internal server error' + } + }; + } +}; + +export default settingsApi; \ No newline at end of file