added endpoints and routes to get sessions
This commit is contained in:
@@ -18,4 +18,14 @@ router.get('/:sessionId/history', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/', async (req, res) => {
|
||||
const {limit = 20, offset = 0 } = req.query;
|
||||
try {
|
||||
const sessions = await memory.getSessions(Number(limit), Number(offset));
|
||||
res.json(sessions);
|
||||
} catch (err) {
|
||||
res.status(500).json({error: err.message});
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = router;
|
||||
@@ -56,11 +56,20 @@ async function getSessionHistory(sessionId, limit = 20, offset = 0) {
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function getSessions(limit = 20, offset = 0) {
|
||||
const res = await fetch(
|
||||
`${BASE_URL}/sessions?limit${limit}&offset=${offset}`
|
||||
);
|
||||
if (!res.ok) throw new Error(`Failed to fetch sessions: ${res.status}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getSessionByExternalId,
|
||||
createSession,
|
||||
getRecentEpisodes,
|
||||
createEpisode,
|
||||
getEpisodeById,
|
||||
getSessionHistory
|
||||
getSessionHistory,
|
||||
getSessions
|
||||
}
|
||||
Reference in New Issue
Block a user