db created, added tests -- tentative
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user