Files
new-phone-who-dis/resources/server/notes/notes.controller.ts
T
Taso 0bb20fff31 refactor(server/notes): Implement singleton architecture
Also trying something out with the response structure on the server to cut down on redundant calls.
2021-04-18 15:38:51 -04:00

33 lines
1.1 KiB
TypeScript

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}`),
);
});