refactoring and clean up
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
require ('dotenv').config();
|
||||
const express = require('express');
|
||||
const {getEnv} = require('@nexusai/shared');
|
||||
const {getEnv, PORTS, EPISODIC} = require('@nexusai/shared');
|
||||
const { getDB } = require('./db');
|
||||
|
||||
const episodic = require('./episodic');
|
||||
const semantic = require('./semantic');
|
||||
const entities = require('./entities');
|
||||
@@ -9,7 +10,7 @@ const entities = require('./entities');
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
|
||||
const PORT = getEnv('PORT', '3002'); // Default to 3002 if PORT is not set
|
||||
const PORT = getEnv('PORT', PORTS.MEMORY);
|
||||
|
||||
//initialize database on startup
|
||||
const db = getDB();
|
||||
@@ -42,7 +43,7 @@ app.post('/sessions', (req, res) => {
|
||||
});
|
||||
|
||||
app.get('/sessions', (req, res) => {
|
||||
const {limit = 20, offset = 0 } = req.query;
|
||||
const {limit = EPISODIC.DEFAULT_PAGE_SIZE, offset = EPISODIC.DEFAULT_OFFSET } = req.query;
|
||||
const sessions = episodic.getSessions(Number(limit), Number(offset));
|
||||
res.json(sessions);
|
||||
})
|
||||
@@ -88,7 +89,7 @@ app.post('/episodes', async (req, res) => {
|
||||
|
||||
// Search MUST come before /:id — otherwise 'search' gets captured as an id
|
||||
app.get('/episodes/search', (req, res) => {
|
||||
const { q, limit = 10 } = req.query;
|
||||
const { q, limit = EPISODIC.DEFAULT_PAGE_SIZE } = req.query;
|
||||
if (!q) return res.status(400).json({ error: 'q (query) parameter is required' });
|
||||
const results = episodic.searchEpisodes(q, Number(limit));
|
||||
res.json(results);
|
||||
@@ -102,7 +103,7 @@ app.get('/episodes/:id', (req, res) => {
|
||||
|
||||
// Get paginated episodes for a session
|
||||
app.get('/sessions/:id/episodes', (req, res) => {
|
||||
const { limit = 10, offset = 0 } = req.query;
|
||||
const { limit = EPISODIC.DEFAULT_PAGE_SIZE, offset = EPISODIC.DEFAULT_OFFSET } = req.query;
|
||||
const episodes = episodic.getEpisodesBySession(
|
||||
req.params.id,
|
||||
Number(limit),
|
||||
|
||||
Reference in New Issue
Block a user