mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
cleanup contacts
This commit is contained in:
1 parent
5debff0ae7
commit
a3d8285265
2 files changed
+20
-19
No files matched your search
@@ -26,8 +26,7 @@ onNet(events.CONTACTS_ADD_CONTACT_SUCCESS, () => {
|
|||||||
|
|
||||||
RegisterNuiCallbackType(events.CONTACTS_UPDATE_CONTACT);
|
RegisterNuiCallbackType(events.CONTACTS_UPDATE_CONTACT);
|
||||||
on(`__cfx_nui:${events.CONTACTS_UPDATE_CONTACT}`, (data: any) => {
|
on(`__cfx_nui:${events.CONTACTS_UPDATE_CONTACT}`, (data: any) => {
|
||||||
const contact = data;
|
emitNet(events.CONTACTS_UPDATE_CONTACT, data)
|
||||||
emitNet(events.CONTACTS_UPDATE_CONTACT, contact)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
onNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, () => {
|
onNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, () => {
|
||||||
@@ -36,14 +35,14 @@ onNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, () => {
|
|||||||
|
|
||||||
RegisterNuiCallbackType(events.CONTACTS_DELETE_CONTACT);
|
RegisterNuiCallbackType(events.CONTACTS_DELETE_CONTACT);
|
||||||
on(`__cfx_nui:${events.CONTACTS_DELETE_CONTACT}`, (data: any) => {
|
on(`__cfx_nui:${events.CONTACTS_DELETE_CONTACT}`, (data: any) => {
|
||||||
const contact = data;
|
emitNet(events.CONTACTS_DELETE_CONTACT, data)
|
||||||
emitNet(events.CONTACTS_DELETE_CONTACT, contact)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
onNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, () => {
|
onNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, () => {
|
||||||
emitNet(events.CONTACTS_GET_CONTACTS)
|
emitNet(events.CONTACTS_GET_CONTACTS)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
onNet(events.CONTACTS_ACTION_RESULT, (result: string) => {
|
onNet(events.CONTACTS_ACTION_RESULT, (result: string) => {
|
||||||
SendNuiMessage(
|
SendNuiMessage(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -52,4 +51,4 @@ onNet(events.CONTACTS_ACTION_RESULT, (result: string) => {
|
|||||||
data: result
|
data: result
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})*/
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ESX } from "./server";
|
import {ESX} from "./server";
|
||||||
import { pool } from "./db";
|
import {pool} from "./db";
|
||||||
import events from "../utils/events";
|
import events from "../utils/events";
|
||||||
import { useIdentifier, getSource } from './functions'
|
import {getSource, useIdentifier} from './functions'
|
||||||
|
|
||||||
interface Contacts {
|
interface Contacts {
|
||||||
id?: number;
|
id?: number;
|
||||||
@@ -18,8 +18,7 @@ interface ContactId {
|
|||||||
async function fetchAllContacts(identifier: string): Promise<Contacts[]> {
|
async function fetchAllContacts(identifier: string): Promise<Contacts[]> {
|
||||||
const query = "SELECT * FROM npwd_phone_contacts WHERE identifier = ?";
|
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[]>results;
|
||||||
return contacts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addContact(
|
async function addContact(
|
||||||
@@ -70,12 +69,13 @@ onNet(events.CONTACTS_ADD_CONTACT, async (number: string, display: string, avata
|
|||||||
try {
|
try {
|
||||||
const _source = (global as any).source;
|
const _source = (global as any).source;
|
||||||
const _identifier = await useIdentifier()
|
const _identifier = await useIdentifier()
|
||||||
addContact(_identifier, number, display, avatar);
|
await addContact(_identifier, number, display, avatar);
|
||||||
emitNet(events.CONTACTS_ADD_CONTACT_SUCCESS, _source)
|
emitNet(events.CONTACTS_ADD_CONTACT_SUCCESS, _source)
|
||||||
emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_ADD_SUCCESS')
|
//emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_ADD_SUCCESS')
|
||||||
|
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_ADD_FAILED')
|
//emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_ADD_FAILED')
|
||||||
|
console.log(error)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -83,21 +83,23 @@ onNet(events.CONTACTS_UPDATE_CONTACT, async (contact: Contacts) => {
|
|||||||
try {
|
try {
|
||||||
const _source = (global as any)._source
|
const _source = (global as any)._source
|
||||||
const _identifier = await useIdentifier()
|
const _identifier = await useIdentifier()
|
||||||
updateContact(contact, _identifier)
|
await updateContact(contact, _identifier)
|
||||||
emitNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, _source)
|
emitNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, _source)
|
||||||
emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_UPDATE_SUCCESS')
|
//emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_UPDATE_SUCCESS')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_UPDATE_FAILED')
|
//emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_UPDATE_FAILED')
|
||||||
|
console.log(error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
onNet(events.CONTACTS_DELETE_CONTACT, async (contact: ContactId) => {
|
onNet(events.CONTACTS_DELETE_CONTACT, async (contact: ContactId) => {
|
||||||
try {
|
try {
|
||||||
const _identifier = await useIdentifier()
|
const _identifier = await useIdentifier()
|
||||||
deleteContact(contact, _identifier)
|
await deleteContact(contact, _identifier)
|
||||||
emitNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, getSource())
|
emitNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, getSource())
|
||||||
emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_DELETE_SUCCESS')
|
//emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_DELETE_SUCCESS')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_DELETE_FAILED')
|
//emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_DELETE_FAILED')
|
||||||
|
console.log(error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Reference in new issue
Block a user