From 9fb4bb97cf45fc2f1d6373f73babded7b02c5538 Mon Sep 17 00:00:00 2001 From: chip Date: Sun, 1 Nov 2020 19:26:24 +0100 Subject: [PATCH] tweak(notes/server): imports of interfaces --- resources/server/sv_notes.ts | 87 ++++++++++++++---------------------- 1 file changed, 34 insertions(+), 53 deletions(-) diff --git a/resources/server/sv_notes.ts b/resources/server/sv_notes.ts index 77a6c7d..b1cd777 100644 --- a/resources/server/sv_notes.ts +++ b/resources/server/sv_notes.ts @@ -1,91 +1,72 @@ -import events from '../utils/events'; -import { ESX, getSource } from './server'; -import { pool } from './db'; -import { useIdentifier } from './functions'; - -interface Note { - id?: number; - title: string; - content: string; -} - -interface NoteId { - id: number -} +import events from "../utils/events"; +import { ESX, getSource } from "./server"; +import { pool } from "./db"; +import { useIdentifier } from "./functions"; +import { Note, NoteId } from "../../phone/src/common/interfaces/notes"; async function addNote(identifier: string, note: Note): Promise { - const query = "INSERT INTO npwd_notes (identifier, title, content) VALUES (?, ?, ?)" - await pool.query(query, - [ - identifier, - note.title, - note.content - ] - ) + const query = + "INSERT INTO npwd_notes (identifier, title, content) VALUES (?, ?, ?)"; + await pool.query(query, [identifier, note.title, note.content]); } async function fetchAllNotes(identifier: string): Promise { - const query = "SELECT * FROM npwd_notes WHERE identifier = ? ORDER BY id DESC" - const [ result ] = await pool.query(query, [identifier]); + const query = + "SELECT * FROM npwd_notes WHERE identifier = ? ORDER BY id DESC"; + const [result] = await pool.query(query, [identifier]); const notes = result; return notes; } async function deleteNote(noteId: number, identifier: string) { const query = "DELETE FROM npwd_notes WHERE id = ? AND identifier = ?"; - await pool.query(query, [noteId, identifier]) + await pool.query(query, [noteId, identifier]); } async function updateNote(note: Note, identifier: string): Promise { - const query = "UPDATE npwd_notes SET title = ?, content = ? WHERE id = ? AND identifier = ?" - await pool.query(query, [ - note.title, - note.content, - note.id, - identifier - ]) + const query = + "UPDATE npwd_notes SET title = ?, content = ? WHERE id = ? AND identifier = ?"; + await pool.query(query, [note.title, note.content, note.id, identifier]); } onNet(events.NOTE_ADD_NOTE, async (note: Note) => { try { - console.log(note.content, note.title); - const _identifier = await useIdentifier() - console.log(_identifier) - addNote(_identifier, note) - } - catch(error) { - console.log("NOTES ERROR: ", error) + const _identifier = await useIdentifier(); + addNote(_identifier, note); + } catch (error) { + console.log("NOTES ERROR: ", error); } -}) +}); onNet(events.NOTE_FETCH_ALL_NOTES, async () => { try { const _source = (global as any).source; - const _identifier = await useIdentifier() + const _identifier = await useIdentifier(); const notes = await fetchAllNotes(_identifier); - emitNet(events.NOTE_SEND_NOTE, _source, notes) + emitNet(events.NOTE_SEND_NOTE, _source, notes); + emitNet(events.NOTE_SEND_NOTE_SUCCESS, _source); } catch (error) { - console.log("NOTE ERROR: ", error) + console.log("NOTE ERROR: ", error); } -}) +}); onNet(events.NOTE_DELETE_NOTE, async (noteId: NoteId) => { try { const _identifier = await useIdentifier(); - const id = noteId.id - await deleteNote(id, _identifier) - } catch(error) { - console.log("NOTE ERROR:", error) + const id = noteId.id; + await deleteNote(id, _identifier); + } catch (error) { + console.log("NOTE ERROR:", error); } -}) +}); onNet(events.NOTE_UPDATE_NOTE, async (note: Note) => { const _source = (global as any).source; try { const _identifier = await useIdentifier(); - updateNote(note, _identifier) - emitNet(events.NOTE_UPDATE_NOTE_SUCCESS, _source) + updateNote(note, _identifier); + emitNet(events.NOTE_UPDATE_NOTE_SUCCESS, _source); } catch (error) { - emitNet(events.NOTE_UPDATE_NOTE_FAILURE, _source) + emitNet(events.NOTE_UPDATE_NOTE_FAILURE, _source); } -}) \ No newline at end of file +});