mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
Mysql connection strings, unit tests, prettier on server
This adds support for the other type of Mysql connection string specified by mysql async. Support for both strings and their respective options are necessary to support backwards compatibility of existing server configurations. This also adds support for jest & unit testing on the server/client and some unit tests for some of the connection string parsing. It runs these test and prettier in a pre-commit hook.
This commit is contained in:
1 parent
8d2e0d9edb
commit
a5d1e54b56
21 files changed
+4136
-505
No files matched your search
@@ -1,21 +1,27 @@
|
||||
import { ESX } from './server';
|
||||
import { pool } from './db';
|
||||
import events from '../utils/events';
|
||||
import { ESX } from "./server";
|
||||
import { pool } from "./db";
|
||||
import events from "../utils/events";
|
||||
|
||||
interface Contacts {
|
||||
display: string;
|
||||
number: string;
|
||||
}
|
||||
|
||||
async function fetchAllContacts(identifier: string) : Promise<Contacts[]> {
|
||||
async function fetchAllContacts(identifier: string): Promise<Contacts[]> {
|
||||
const query = "SELECT * FROM npwd_phone_contacts WHERE identifier = ?";
|
||||
const [ results ] = await pool.query(query, [identifier]);
|
||||
const [results] = await pool.query(query, [identifier]);
|
||||
const contacts = <Contacts[]>results;
|
||||
return contacts;
|
||||
}
|
||||
|
||||
async function addContact(identifier: string, number: string, display: string, avatar: string):Promise<any> {
|
||||
const query = "INSERT INTO npwd_phone_contacts (identifier, number, display, avatar) VALUES (?, ?, ?, ?)"
|
||||
async function addContact(
|
||||
identifier: string,
|
||||
number: string,
|
||||
display: string,
|
||||
avatar: string
|
||||
): Promise<any> {
|
||||
const query =
|
||||
"INSERT INTO npwd_phone_contacts (identifier, number, display, avatar) VALUES (?, ?, ?, ?)";
|
||||
|
||||
await pool.query(query, [identifier, number, display, avatar]);
|
||||
}
|
||||
@@ -27,22 +33,23 @@ onNet(events.CONTACTS_GET_CONTACTS, async () => {
|
||||
const _identifier = xPlayer.getIdentifier();
|
||||
|
||||
const contacts = await fetchAllContacts(_identifier);
|
||||
emitNet(events.CONTACTS_SEND_CONTACTS, _source, contacts)
|
||||
|
||||
} catch(error) {
|
||||
emitNet(events.CONTACTS_SEND_CONTACTS, _source, contacts);
|
||||
} catch (error) {
|
||||
console.log("Failed to fetch contacts: ", error);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
onNet(events.CONTACTS_ADD_CONTACT, (number: string, display: string, avatar: string) => {
|
||||
try {
|
||||
const _source = (global as any).source;
|
||||
const xPlayer = ESX.GetPlayerFromId(_source);
|
||||
const _identifier = xPlayer.getIdentifier()
|
||||
addContact(_identifier, number, display, avatar);
|
||||
emit(events.CONTACTS_GET_CONTACTS);
|
||||
|
||||
} catch(error) {
|
||||
console.log("Failed to add contact: ", error);
|
||||
onNet(
|
||||
events.CONTACTS_ADD_CONTACT,
|
||||
(number: string, display: string, avatar: string) => {
|
||||
try {
|
||||
const _source = (global as any).source;
|
||||
const xPlayer = ESX.GetPlayerFromId(_source);
|
||||
const _identifier = xPlayer.getIdentifier();
|
||||
addContact(_identifier, number, display, avatar);
|
||||
emit(events.CONTACTS_GET_CONTACTS);
|
||||
} catch (error) {
|
||||
console.log("Failed to add contact: ", error);
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
Reference in new issue
Block a user