feat(notes/client|server): sending alert results!

This commit is contained in:
Christopher committed 2021-02-08 18:54:13 +01:00
1 parent 4d92847163
commit a8f025aff3
5 files changed
+46 -29

No files matched your search

+27 -15
View File
@@ -13,8 +13,7 @@ async function fetchAllNotes(identifier: string): Promise<Note[]> {
const query =
'SELECT * FROM npwd_notes WHERE identifier = ? ORDER BY id DESC';
const [result] = await pool.query(query, [identifier]);
const notes = <Note[]>result;
return notes;
return <Note[]>result;
}
async function deleteNote(noteId: number, identifier: string) {
@@ -30,42 +29,55 @@ async function updateNote(note: Note, identifier: string): Promise<any> {
onNet(events.NOTE_ADD_NOTE, async (note: Note) => {
try {
const pSource = (global as any).source
const _identifier = await useIdentifier();
addNote(_identifier, note);
emitNet(events.NOTE_SEND_NOTE_SUCCESS, getSource());
await addNote(_identifier, note);
emitNet(events.NOTE_SEND_NOTE_SUCCESS, pSource);
emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_ADD_SUCCESS')
} catch (error) {
console.log('NOTES ERROR: ', error);
const pSource = (global as any).source
emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_ADD_FAILED')
}
});
onNet(events.NOTE_FETCH_ALL_NOTES, async () => {
try {
const _source = (global as any).source;
const pSource = (global as any).source
const _identifier = await useIdentifier();
const notes = await fetchAllNotes(_identifier);
emitNet(events.NOTE_SEND_NOTE, _source, notes);
emitNet(events.NOTE_SEND_NOTE, pSource, notes);
} catch (error) {
console.log('NOTE ERROR: ', error);
console.dir(error)
}
});
onNet(events.NOTE_DELETE_NOTE, async (noteId: NoteId) => {
try {
const pSource = (global as any).source;
const _identifier = await useIdentifier();
const id = noteId.id;
await deleteNote(id, _identifier);
await deleteNote(noteId.id, _identifier);
emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_DELETE_SUCCESS')
} catch (error) {
console.log('NOTE ERROR:', error);
const pSource = (global as any).source;
emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_DELETE_FAILED')
}
});
onNet(events.NOTE_UPDATE_NOTE, async (note: Note) => {
const _source = (global as any).source;
try {
const pSource = (global as any).source;
const _identifier = await useIdentifier();
updateNote(note, _identifier);
emitNet(events.NOTE_UPDATE_NOTE_SUCCESS, _source);
await updateNote(note, _identifier);
emitNet(events.NOTE_UPDATE_NOTE_SUCCESS, pSource);
emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_UPDATE_SUCCESS')
} catch (error) {
emitNet(events.NOTE_UPDATE_NOTE_FAILURE, _source);
const pSource = (global as any).source;
emitNet(events.NOTE_UPDATE_NOTE_FAILURE, pSource);
}
});