added project express routes
This commit is contained in:
@@ -3,7 +3,8 @@ const express = require('express');
|
||||
const {getEnv, PORTS, SERVICES, ORCHESTRATION} = require('@nexusai/shared');
|
||||
const chatRouter = require('./routes/chat');
|
||||
const sessionsRouter = require('./routes/sessions');
|
||||
const modelsRouter = require('./routes/models')
|
||||
const modelsRouter = require('./routes/models');
|
||||
const projectsRouter = require('./routes/projects');
|
||||
const cors = require('cors');
|
||||
|
||||
const app = express();
|
||||
@@ -37,6 +38,7 @@ app.get('/health', (req, res) => {
|
||||
app.use('/chat', chatRouter);
|
||||
app.use('/sessions', sessionsRouter);
|
||||
app.use('/models', modelsRouter);
|
||||
app.use('/projects', projectsRouter);
|
||||
|
||||
/******* Start the server ************/
|
||||
app.listen(PORT, () => {
|
||||
|
||||
41
packages/orchestration-service/src/routes/projects.js
Normal file
41
packages/orchestration-service/src/routes/projects.js
Normal file
@@ -0,0 +1,41 @@
|
||||
const { Router } = require('express');
|
||||
const memory = require('../services/memory');
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
res.json(await memory.getProjects());
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
const { name, description, colour, icon } = req.body;
|
||||
if (!name?.trim()) return res.status(400).json({ error: 'name is required' });
|
||||
try {
|
||||
res.status(201).json(await memory.createProject({ name: name.trim(), description, colour, icon }));
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
router.patch('/:id', async (req, res) => {
|
||||
try {
|
||||
res.json(await memory.updateProject(req.params.id, req.body));
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/:id', async (req, res) => {
|
||||
try {
|
||||
await memory.deleteProject(req.params.id);
|
||||
res.status(204).send();
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -80,6 +80,38 @@ async function deleteSession(externalId) {
|
||||
if (!res.ok) throw new Error(`Failed to delete session: ${res.status}`);
|
||||
}
|
||||
|
||||
/******** PROJECTS ********* */
|
||||
async function createProject({ name, description, colour, icon }) {
|
||||
const res = await fetch(`${BASE_URL}/projects`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name, description, colour, icon })
|
||||
});
|
||||
if (!res.ok) throw new Error(`Failed to create project: ${res.status}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function getProjects() {
|
||||
const res = await fetch(`${BASE_URL}/projects`);
|
||||
if (!res.ok) throw new Error(`Failed to fetch projects: ${res.status}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function updateProject(id, { name, description, colour, icon }) {
|
||||
const res = await fetch(`${BASE_URL}/projects/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name, description, colour, icon })
|
||||
});
|
||||
if (!res.ok) throw new Error(`Failed to update project: ${res.status}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function deleteProject(id) {
|
||||
const res = await fetch(`${BASE_URL}/projects/${id}`, { method: 'DELETE' });
|
||||
if (!res.ok) throw new Error(`Failed to delete project: ${res.status}`);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getSessionByExternalId,
|
||||
createSession,
|
||||
@@ -90,4 +122,8 @@ module.exports = {
|
||||
getSessions,
|
||||
updateSession,
|
||||
deleteSession,
|
||||
createProject,
|
||||
getProjects,
|
||||
updateProject,
|
||||
deleteProject,
|
||||
}
|
||||
Reference in New Issue
Block a user