fix for persistant settings management
This commit is contained in:
parent
5b882f4e13
commit
f321bfe41e
|
@ -1,15 +1,15 @@
|
|||
import express from 'express';
|
||||
import db from '../db';
|
||||
import { settings } from '../db/schema';
|
||||
|
||||
import { settings, eq } from '../db/schema';
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
try {
|
||||
const { chatModelProvider, chatModel, embeddingModelProvider, embeddingModel, openAIApiKey, openAIBaseURL } = req.body;
|
||||
|
||||
// TODO: Add user authentication
|
||||
|
||||
await db.delete(settings).execute();
|
||||
|
||||
await db.insert(settings).values({
|
||||
chatModelProvider,
|
||||
chatModel,
|
||||
|
@ -21,6 +21,7 @@ router.post('/', async (req, res) => {
|
|||
|
||||
res.status(200).json({ message: 'Settings saved successfully' });
|
||||
} catch (err) {
|
||||
console.error('Error saving settings:', err);
|
||||
res.status(500).json({ message: 'An error occurred while saving settings' });
|
||||
}
|
||||
});
|
||||
|
@ -29,8 +30,12 @@ router.get('/', async (req, res) => {
|
|||
try {
|
||||
// TODO: Add user authentication
|
||||
const userSettings = await db.query.settings.findFirst();
|
||||
if (!userSettings) {
|
||||
return res.status(404).json({ message: 'No settings found' });
|
||||
}
|
||||
res.status(200).json(userSettings);
|
||||
} catch (err) {
|
||||
console.error('Error fetching settings:', err);
|
||||
res.status(500).json({ message: 'An error occurred while fetching settings' });
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue