summaryrefslogtreecommitdiff
path: root/src/notes.js
diff options
context:
space:
mode:
authorLeo Goetz <dev@leogtz.de>2025-11-09 14:19:26 +0100
committerLeo Goetz <dev@leogtz.de>2025-11-09 14:19:26 +0100
commit789d28b83af165258dc7e8b3a44bbd2d48fcc370 (patch)
treee98ef728fb42a7bc03aef6d6a601e0533a4961b3 /src/notes.js
parent16a0e9a9d2c24af28142ed3420ef6cb373c454f7 (diff)
added crud functionality with json file as a db
Diffstat (limited to 'src/notes.js')
-rw-r--r--src/notes.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/notes.js b/src/notes.js
new file mode 100644
index 0000000..7a34950
--- /dev/null
+++ b/src/notes.js
@@ -0,0 +1,37 @@
+import { getDB, saveDB, insertDB } from "./db.js";
+
+export const newNote = async (note, tags) => {
+ const newNote = {
+ tags,
+ id: Date.now(),
+ content: note,
+ };
+
+ await insertDB(newNote);
+ return newNote;
+};
+
+export const getAllNotes = async () => {
+ const { notes } = await getDB();
+ return notes;
+};
+
+export const findNotes = async (filter) => {
+ const { notes } = await getDB();
+ return notes.filter((note) =>
+ note.content.toLowerCase().includes(filter.toLowerCase()),
+ );
+};
+
+export const removeNote = async (id) => {
+ const { notes } = await getDB();
+ const match = notes.find((note) => note.id === id);
+
+ if (match) {
+ const newNotes = notes.filter((note) => note.id !== id);
+ await saveDB({ notes: newNotes });
+ return id;
+ }
+};
+
+export const removeAllNotes = () => saveDB({ notes: [] });