refactor(server/notes): Implement singleton architecture

Also trying something out with the response structure on the server to cut down on redundant calls.
This commit is contained in:
Taso committed 2021-04-18 15:38:51 -04:00
1 parent d93bdd20d8
commit 0bb20fff31
8 files changed
+219 -136

No files matched your search

@@ -0,0 +1,32 @@
import { Note, NotesEvents } from '../../../typings/notes';
import { getSource } from '../utils/miscUtils';
import NotesService from './notes.service';
import { notesLogger } from './notes.utils';
onNet(NotesEvents.ADD_NOTE, (note: Note) => {
const src = getSource();
NotesService.handleAddNote(src, note).catch((e) =>
notesLogger.error(`Error occured in add note event (${src}), Error: ${e.message}`),
);
});
onNet(NotesEvents.FETCH_ALL_NOTES, async (limit?: number) => {
const src = getSource();
NotesService.handleFetchNotes(src, limit).catch((e) =>
notesLogger.error(`Error occured in fetch note event (${src}), Error: ${e.message}`),
);
});
onNet(NotesEvents.DELETE_NOTE, async (noteId: number) => {
const src = getSource();
NotesService.handleDeleteNote(src, noteId).catch((e) =>
notesLogger.error(`Error occured in delete note event (${src}), Error: ${e.message}`),
);
});
onNet(NotesEvents.UPDATE_NOTE, async (note: Note) => {
const src = getSource();
NotesService.handleUpdateNote(src, note).catch((e) =>
notesLogger.error(`Error occured in fetch note event (${src}), Error: ${e.message}`),
);
});