mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +00:00
fix(server/notes): Temporarily use old resp format
This commit is contained in:
1 parent
635dc907ce
commit
8af7530f18
2 files changed
+38
-66
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
import { Note, NoteServerResponse, NotesEvents } from '../../typings/notes';
|
import { Note, NotesEvents } from '../../typings/notes';
|
||||||
import { sendNotesEvent } from '../utils/messages';
|
import { sendNotesEvent } from '../utils/messages';
|
||||||
|
|
||||||
onNet(NotesEvents.SEND_NOTE, (notes: any) => {
|
onNet(NotesEvents.SEND_NOTE, (notes: any) => {
|
||||||
@@ -20,22 +20,14 @@ on(`__cfx_nui:${NotesEvents.UPDATE_NOTE}`, (note: Note) => {
|
|||||||
emitNet(NotesEvents.UPDATE_NOTE, note);
|
emitNet(NotesEvents.UPDATE_NOTE, note);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Trying out this response structure
|
onNet(NotesEvents.UPDATE_NOTE_SUCCESS, () => {
|
||||||
onNet(
|
|
||||||
NotesEvents.SERVER_RESP,
|
|
||||||
({ alert, action, suceeded, refetch, data }: NoteServerResponse<Note[] | Note>) => {
|
|
||||||
if (alert) {
|
|
||||||
sendNotesEvent(NotesEvents.SEND_ALERT, alert);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (action) {
|
|
||||||
case 'SEND':
|
|
||||||
sendNotesEvent(NotesEvents.SEND_NOTE, data);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (refetch && suceeded) {
|
|
||||||
emitNet(NotesEvents.FETCH_ALL_NOTES);
|
emitNet(NotesEvents.FETCH_ALL_NOTES);
|
||||||
}
|
});
|
||||||
},
|
|
||||||
);
|
onNet(NotesEvents.ACTION_RESULT, (alert: any) => {
|
||||||
|
sendNotesEvent(NotesEvents.SEND_ALERT, alert);
|
||||||
|
});
|
||||||
|
|
||||||
|
onNet(NotesEvents.DELETE_NOTE_SUCCESS, () => {
|
||||||
|
emitNet(NotesEvents.FETCH_ALL_NOTES);
|
||||||
|
});
|
||||||
@@ -8,39 +8,30 @@ class _NotesService {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.notesDB = NotesDB;
|
this.notesDB = NotesDB;
|
||||||
|
notesLogger.debug('Notes service started');
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleAddNote(src: number, note: Note): Promise<void> {
|
async handleAddNote(src: number, note: Note): Promise<void> {
|
||||||
notesLogger.debug('Handling add note, note:');
|
notesLogger.debug('Handling add note, note:');
|
||||||
notesLogger.debug(note);
|
notesLogger.debug(note);
|
||||||
|
|
||||||
const identifer = PlayerService.getIdentifier(src);
|
const identifer = PlayerService.getIdentifier(src);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.notesDB.addNote(identifer, note);
|
await this.notesDB.addNote(identifer, note);
|
||||||
|
|
||||||
const serverRespObj: NoteServerResponse = {
|
emitNet(NotesEvents.SEND_NOTE_SUCCESS, src);
|
||||||
action: 'ADD',
|
emitNet(NotesEvents.ACTION_RESULT, src, {
|
||||||
suceeded: true,
|
|
||||||
refetch: true,
|
|
||||||
alert: {
|
|
||||||
message: 'NOTES_ADD_SUCCESS',
|
message: 'NOTES_ADD_SUCCESS',
|
||||||
type: 'success',
|
type: 'success',
|
||||||
},
|
});
|
||||||
};
|
|
||||||
|
|
||||||
emitNet(NotesEvents.SERVER_RESP, src, serverRespObj);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
notesLogger.error(`Error in handleAddNote, ${e.message}`);
|
notesLogger.error(`Error in handleAddNote, ${e.message}`);
|
||||||
|
|
||||||
const serverRespObj: NoteServerResponse = {
|
emitNet(NotesEvents.ACTION_RESULT, src, {
|
||||||
action: 'ADD',
|
|
||||||
suceeded: false,
|
|
||||||
alert: {
|
|
||||||
message: 'NOTES_ADD_FAILED',
|
message: 'NOTES_ADD_FAILED',
|
||||||
type: 'success',
|
type: 'error',
|
||||||
},
|
});
|
||||||
};
|
|
||||||
|
|
||||||
emitNet(NotesEvents.SERVER_RESP, src, serverRespObj);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,13 +39,7 @@ class _NotesService {
|
|||||||
const identifier = PlayerService.getIdentifier(src);
|
const identifier = PlayerService.getIdentifier(src);
|
||||||
try {
|
try {
|
||||||
const notes = await this.notesDB.fetchNotes(identifier, limit);
|
const notes = await this.notesDB.fetchNotes(identifier, limit);
|
||||||
const serverRespObj: NoteServerResponse = {
|
emitNet(NotesEvents.SEND_NOTE, src, notes);
|
||||||
action: 'SEND',
|
|
||||||
suceeded: false,
|
|
||||||
data: notes,
|
|
||||||
refetch: false,
|
|
||||||
};
|
|
||||||
emitNet(NotesEvents.SEND_NOTE, src, serverRespObj);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
notesLogger.error(`Error in handleFetchNote, ${e.message}`);
|
notesLogger.error(`Error in handleFetchNote, ${e.message}`);
|
||||||
}
|
}
|
||||||
@@ -64,12 +49,18 @@ class _NotesService {
|
|||||||
const identifier = PlayerService.getIdentifier(src);
|
const identifier = PlayerService.getIdentifier(src);
|
||||||
try {
|
try {
|
||||||
await this.notesDB.updateNote(note, identifier);
|
await this.notesDB.updateNote(note, identifier);
|
||||||
const serverRespObj: NoteServerResponse = {
|
emitNet(NotesEvents.UPDATE_NOTE_SUCCESS, src);
|
||||||
action: 'UPDATE',
|
|
||||||
suceeded: true,
|
emitNet(NotesEvents.ACTION_RESULT, src, {
|
||||||
refetch: true,
|
message: 'NOTES_UPDATE_SUCCESS',
|
||||||
};
|
type: 'success',
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
emitNet(NotesEvents.UPDATE_NOTE_FAILURE, src);
|
||||||
|
emitNet(NotesEvents.ACTION_RESULT, src, {
|
||||||
|
message: 'NOTES_UPDATE_FAILED',
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
notesLogger.error(`Error in handleUpdateNote, ${e.message}`);
|
notesLogger.error(`Error in handleUpdateNote, ${e.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,29 +74,18 @@ class _NotesService {
|
|||||||
try {
|
try {
|
||||||
await this.notesDB.deleteNote(noteId, identifier);
|
await this.notesDB.deleteNote(noteId, identifier);
|
||||||
|
|
||||||
const serverRespObj: NoteServerResponse = {
|
emitNet(NotesEvents.DELETE_NOTE_SUCCESS, src);
|
||||||
action: 'DELETE',
|
|
||||||
suceeded: true,
|
emitNet(NotesEvents.ACTION_RESULT, src, {
|
||||||
refetch: true,
|
|
||||||
alert: {
|
|
||||||
message: 'NOTES_DELETE_SUCCESS',
|
message: 'NOTES_DELETE_SUCCESS',
|
||||||
type: 'success',
|
type: 'success',
|
||||||
},
|
});
|
||||||
};
|
|
||||||
|
|
||||||
emitNet(NotesEvents.DELETE_NOTE, src, serverRespObj);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
notesLogger.error(`Error in handleDeleteNote, ${e.message}`);
|
notesLogger.error(`Error in handleDeleteNote, ${e.message}`);
|
||||||
const serverRespObj: NoteServerResponse = {
|
emitNet(NotesEvents.ACTION_RESULT, src, {
|
||||||
action: 'DELETE',
|
|
||||||
suceeded: false,
|
|
||||||
alert: {
|
|
||||||
message: 'NOTES_DELETE_FAILED',
|
message: 'NOTES_DELETE_FAILED',
|
||||||
type: 'error',
|
type: 'error',
|
||||||
},
|
});
|
||||||
};
|
|
||||||
|
|
||||||
emitNet(NotesEvents.DELETE_NOTE, src, serverRespObj);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user