remove eq from db schema import
This commit is contained in:
parent
b1b1db184d
commit
7d9012b99f
|
@ -1,43 +1,43 @@
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import db from '../db';
|
import db from '../db';
|
||||||
import { settings, eq } from '../db/schema';
|
import { settings } from '../db/schema';
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.post('/', async (req, res) => {
|
router.post('/', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { chatModelProvider, chatModel, embeddingModelProvider, embeddingModel, openAIApiKey, openAIBaseURL } = req.body;
|
const { chatModelProvider, chatModel, embeddingModelProvider, embeddingModel, openAIApiKey, openAIBaseURL } = req.body;
|
||||||
// TODO: Add user authentication
|
// TODO: Add user authentication
|
||||||
|
|
||||||
await db.delete(settings).execute();
|
await db.delete(settings).execute();
|
||||||
|
|
||||||
await db.insert(settings).values({
|
await db.insert(settings).values({
|
||||||
chatModelProvider,
|
chatModelProvider,
|
||||||
chatModel,
|
chatModel,
|
||||||
embeddingModelProvider,
|
embeddingModelProvider,
|
||||||
embeddingModel,
|
embeddingModel,
|
||||||
openAIApiKey,
|
openAIApiKey,
|
||||||
openAIBaseURL,
|
openAIBaseURL,
|
||||||
}).execute();
|
}).execute();
|
||||||
|
|
||||||
res.status(200).json({ message: 'Settings saved successfully' });
|
res.status(200).json({ message: 'Settings saved successfully' });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error saving settings:', err);
|
console.error('Error saving settings:', err);
|
||||||
res.status(500).json({ message: 'An error occurred while saving settings' });
|
res.status(500).json({ message: 'An error occurred while saving settings' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/', async (req, res) => {
|
router.get('/', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
// TODO: Add user authentication
|
// TODO: Add user authentication
|
||||||
const userSettings = await db.query.settings.findFirst();
|
const userSettings = await db.query.settings.findFirst();
|
||||||
if (!userSettings) {
|
if (!userSettings) {
|
||||||
return res.status(404).json({ message: 'No settings found' });
|
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' });
|
||||||
}
|
}
|
||||||
res.status(200).json(userSettings);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching settings:', err);
|
|
||||||
res.status(500).json({ message: 'An error occurred while fetching settings' });
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
Loading…
Reference in New Issue