db created, added tests -- tentative

This commit is contained in:
KS Jannette
2026-02-24 19:25:42 -05:00
parent 0ee426e1f3
commit ce7bc2cde9
10 changed files with 447 additions and 38 deletions

View File

@@ -1,18 +1,12 @@
import { Router } from 'express';
import { readFile } from 'fs/promises';
import { getAllNotes } from '../db/notes.dao.js';
import { clusterNotes } from '../services/clustering.service.js';
const router = Router();
const DATA_PATH = new URL('../data/notes.json', import.meta.url);
const loadNotes = async () => {
const raw = await readFile(DATA_PATH, 'utf-8');
return JSON.parse(raw);
};
router.get('/', async (req, res) => {
try {
const notes = await loadNotes();
const notes = await getAllNotes();
res.json(notes);
} catch (err) {
console.error(`Error loading notes: ${err}`);
@@ -22,7 +16,7 @@ router.get('/', async (req, res) => {
router.post('/cluster', async (req, res) => {
try {
const notes = await loadNotes();
const notes = await getAllNotes();
const result = await clusterNotes(notes);
res.json(result);
} catch (err) {