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

+12 -14
View File
@@ -1,19 +1,13 @@
import events from '../utils/events';
import { sendNotesEvent } from '../utils/messages';
onNet(events.NOTE_SEND_NOTE, (notes: any) => {
SendNuiMessage(
JSON.stringify({
app: 'NOTES',
method: 'setNotes',
data: notes,
})
);
sendNotesEvent('setNotes', notes);
});
RegisterNuiCallbackType(events.NOTE_ADD_NOTE);
on(`__cfx_nui:${events.NOTE_ADD_NOTE}`, (data: any) => {
const note = data;
emitNet(events.NOTE_ADD_NOTE, note);
emitNet(events.NOTE_ADD_NOTE, data);
});
onNet(events.NOTE_SEND_NOTE_SUCCESS, () => {
@@ -22,18 +16,22 @@ onNet(events.NOTE_SEND_NOTE_SUCCESS, () => {
RegisterNuiCallbackType(events.NOTE_DELETE_NOTE);
on(`__cfx_nui:${events.NOTE_DELETE_NOTE}`, (data: any) => {
const noteId = data;
emitNet(events.NOTE_DELETE_NOTE, noteId);
emitNet(events.NOTE_DELETE_NOTE, data);
emitNet(events.NOTE_FETCH_ALL_NOTES);
});
RegisterNuiCallbackType(events.NOTE_UPDATE_NOTE);
on(`__cfx_nui:${events.NOTE_UPDATE_NOTE}`, (data: any) => {
const note = data;
emitNet(events.NOTE_UPDATE_NOTE, note);
emitNet(events.NOTE_UPDATE_NOTE, data);
});
onNet(events.NOTE_UPDATE_NOTE_SUCCESS, () => {
emitNet(events.NOTE_FETCH_ALL_NOTES);
});
onNet(events.NOTE_ACTION_RESULT, (type: string) => {
console.log(type)
sendNotesEvent('setAlert', type)
})
+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);
}
});
+1
View File
@@ -1,4 +1,5 @@
export default {
TWITTER: 'TWITTER',
MESSAGES: 'MESSAGES',
NOTES: 'NOTES'
};
+2
View File
@@ -76,6 +76,8 @@ export default {
NOTE_UPDATE_NOTE: 'phone:updateNote',
NOTE_UPDATE_NOTE_SUCCESS: 'phone:updateNoteSuccess',
NOTE_UPDATE_NOTE_FAILURE: 'phone:updateNoteFailure',
NOTE_ACTION_RESULT: 'phone:notesActionResult',
// DO NOT CHANGE WHATS BELOW, PLEASE - CHIP
OPEN_APP_CONTACTS: 'phone:app:CONTACTS',
+4
View File
@@ -17,3 +17,7 @@ export function sendTwitterMessage(method: string, data: any = {}) {
export function sendMessageEvent(method: string, data: any = {}) {
return sendMessage(apps.MESSAGES, method, data);
}
export function sendNotesEvent(method: string, data: any = {}) {
return sendMessage(apps.NOTES, method, data);
}