cleanup contacts

This commit is contained in:
Christopher committed 2021-01-03 21:40:05 +01:00
1 parent 5debff0ae7
commit a3d8285265
2 files changed
+20 -19

No files matched your search

+4 -5
View File
@@ -26,8 +26,7 @@ onNet(events.CONTACTS_ADD_CONTACT_SUCCESS, () => {
RegisterNuiCallbackType(events.CONTACTS_UPDATE_CONTACT);
on(`__cfx_nui:${events.CONTACTS_UPDATE_CONTACT}`, (data: any) => {
const contact = data;
emitNet(events.CONTACTS_UPDATE_CONTACT, contact)
emitNet(events.CONTACTS_UPDATE_CONTACT, data)
})
onNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, () => {
@@ -36,14 +35,14 @@ onNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, () => {
RegisterNuiCallbackType(events.CONTACTS_DELETE_CONTACT);
on(`__cfx_nui:${events.CONTACTS_DELETE_CONTACT}`, (data: any) => {
const contact = data;
emitNet(events.CONTACTS_DELETE_CONTACT, contact)
emitNet(events.CONTACTS_DELETE_CONTACT, data)
})
onNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, () => {
emitNet(events.CONTACTS_GET_CONTACTS)
})
/*
onNet(events.CONTACTS_ACTION_RESULT, (result: string) => {
SendNuiMessage(
JSON.stringify({
@@ -52,4 +51,4 @@ onNet(events.CONTACTS_ACTION_RESULT, (result: string) => {
data: result
})
)
})
})*/
+16 -14
View File
@@ -1,7 +1,7 @@
import { ESX } from "./server";
import { pool } from "./db";
import {ESX} from "./server";
import {pool} from "./db";
import events from "../utils/events";
import { useIdentifier, getSource } from './functions'
import {getSource, useIdentifier} from './functions'
interface Contacts {
id?: number;
@@ -18,8 +18,7 @@ interface ContactId {
async function fetchAllContacts(identifier: string): Promise<Contacts[]> {
const query = "SELECT * FROM npwd_phone_contacts WHERE identifier = ?";
const [results] = await pool.query(query, [identifier]);
const contacts = <Contacts[]>results;
return contacts;
return <Contacts[]>results;
}
async function addContact(
@@ -70,12 +69,13 @@ onNet(events.CONTACTS_ADD_CONTACT, async (number: string, display: string, avata
try {
const _source = (global as any).source;
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_ACTION_RESULT, getSource(), 'CONTACT_ADD_SUCCESS')
//emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_ADD_SUCCESS')
} 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 {
const _source = (global as any)._source
const _identifier = await useIdentifier()
updateContact(contact, _identifier)
await updateContact(contact, _identifier)
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) {
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) => {
try {
const _identifier = await useIdentifier()
deleteContact(contact, _identifier)
await deleteContact(contact, _identifier)
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) {
emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_DELETE_FAILED')
//emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_DELETE_FAILED')
console.log(error)
}
})