summaryrefslogtreecommitdiff
path: root/src/notes.js
diff options
context:
space:
mode:
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: [] });