narinder1231 commited on
Commit
29c46e8
·
1 Parent(s): 41de39d

expose an api to get setting by id

Browse files
src/controllers/setting.controller.ts CHANGED
@@ -92,4 +92,21 @@ const getSettings = async (req: Request, res: Response) => {
92
  }
93
  }
94
 
95
- export { getSettings }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  }
93
  }
94
 
95
+ const getSettingById = async (req: Request, res: Response) => {
96
+ try {
97
+ const { id } = req.params;
98
+
99
+ const setting = await Setting.findByPk(id);
100
+
101
+ if (!setting) {
102
+ return res.status(404).json({ error: 'Setting not found' });
103
+ }
104
+
105
+ return res.status(200).json(setting);
106
+ } catch (error) {
107
+ console.error('Error fetching setting:', error);
108
+ return res.status(500).json({ error: 'Error fetching setting' });
109
+ }
110
+ }
111
+
112
+ export { getSettings, getSettingById };
src/routes/settings.routes.ts CHANGED
@@ -1,8 +1,8 @@
1
  import express from 'express';
2
- import { getSettings } from '../controllers/setting.controller';
3
 
4
  const settingRouter = express.Router();
5
 
6
  settingRouter.get('/', getSettings);
7
-
8
  export default settingRouter
 
1
  import express from 'express';
2
+ import { getSettings, getSettingById } from '../controllers/setting.controller';
3
 
4
  const settingRouter = express.Router();
5
 
6
  settingRouter.get('/', getSettings);
7
+ settingRouter.get('/:id', getSettingById);
8
  export default settingRouter