mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-02 14:38:46 +00:00
fix(sellout:client:server): fixed how stuff gets sent and fetched.
This commit is contained in:
1 parent
98176bf5f3
commit
fbb9ab2ae8
2 files changed
+45
-33
No files matched your search
@@ -1,15 +1,5 @@
|
||||
import events from '../utils/events';
|
||||
|
||||
RegisterNuiCallbackType(events.SELLOUT_ADD_LISTING);
|
||||
on(`__cfx_nui:${events.SELLOUT_ADD_LISTING}`, (data: any) => {
|
||||
emitNet(events.SELLOUT_ADD_LISTING, data)
|
||||
|
||||
setTimeout(() => {
|
||||
emitNet(events.SELLOUT_FETCH_LISTING);
|
||||
console.log("Fetched")
|
||||
}, 500)
|
||||
})
|
||||
|
||||
onNet(events.SELLOUT_SEND_LISTING, (listing: any) => {
|
||||
SendNuiMessage(
|
||||
JSON.stringify({
|
||||
@@ -18,4 +8,16 @@ onNet(events.SELLOUT_SEND_LISTING, (listing: any) => {
|
||||
data: listing
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
RegisterNuiCallbackType(events.SELLOUT_ADD_LISTING);
|
||||
on(`__cfx_nui:${events.SELLOUT_ADD_LISTING}`, (data: any) => {
|
||||
const listing = data;
|
||||
emitNet(events.SELLOUT_ADD_LISTING, listing)
|
||||
|
||||
setTimeout(() => {
|
||||
emitNet(events.SELLOUT_FETCH_LISTING);
|
||||
console.log("Fetched")
|
||||
}, 500)
|
||||
})
|
||||
|
||||
@@ -1,51 +1,61 @@
|
||||
|
||||
import events from '../utils/events';
|
||||
import { ESX, getSource } from './server';
|
||||
import { pool } from './db';
|
||||
import { usePhoneNumber } from './functions';
|
||||
|
||||
|
||||
interface IListing {
|
||||
interface Listing {
|
||||
title: string;
|
||||
name: string;
|
||||
url: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
async function addListing(identifier: string, name: string, title: string, url: string, description: string): Promise<any> {
|
||||
const query = "INSERT INTO npwd_sellout_listings (identifier, name, title, url, description) VALUES (?, ?, ?, ?, ?)"
|
||||
console.log("hallllllollooooo");
|
||||
await pool.query(query, [identifier, name, title, url, description])
|
||||
}
|
||||
|
||||
async function fetchAllListings(): Promise<IListing[]> {
|
||||
async function fetchAllListings(): Promise<Listing[]> {
|
||||
const query = "SELECT * FROM npwd_sellout_listings ORDER BY id DESC";
|
||||
|
||||
const [ results ] = await pool.query(query);
|
||||
const listings = <IListing[]>results;
|
||||
const listings = <Listing[]>results;
|
||||
|
||||
return listings;
|
||||
}
|
||||
|
||||
onNet(events.SELLOUT_ADD_LISTING, (data: any) => {
|
||||
try {
|
||||
const xPlayer = ESX.GetPlayerFromId(getSource())
|
||||
const _identifier = xPlayer.getIdentifier()
|
||||
const name = xPlayer.getName()
|
||||
console.log("ADDED")
|
||||
|
||||
addListing(_identifier, name, data.title, data.url, data.desc)
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
})
|
||||
async function addListing(identifier: string, name: string, number: any, listing: Listing): Promise<any> {
|
||||
const query = "INSERT INTO npwd_sellout_listings (identifier, name, number, title, url, description) VALUES (?, ?, ?, ?, ?, ?)"
|
||||
await pool.query(query, [
|
||||
identifier,
|
||||
name,
|
||||
number,
|
||||
listing.title,
|
||||
listing.url,
|
||||
listing.description,
|
||||
])
|
||||
}
|
||||
|
||||
onNet(events.SELLOUT_FETCH_LISTING, async () => {
|
||||
try {
|
||||
console.log("Fetching all listings")
|
||||
|
||||
const _source = (global as any).source;
|
||||
const listings = await fetchAllListings();
|
||||
console.log("ADDED")
|
||||
emitNet(events.SELLOUT_SEND_LISTING, getSource(), listings)
|
||||
emitNet(events.SELLOUT_SEND_LISTING, _source, listings)
|
||||
|
||||
} catch(error) {
|
||||
console.log(error)
|
||||
}
|
||||
})
|
||||
|
||||
onNet(events.SELLOUT_ADD_LISTING, (listing: Listing) => {
|
||||
try {
|
||||
const xPlayer = ESX.GetPlayerFromId(getSource())
|
||||
const _identifier = xPlayer.getIdentifier()
|
||||
const name = xPlayer.getName()
|
||||
|
||||
const number = "3333333" //usePhoneNumber(_identifier)
|
||||
addListing(_identifier, name, number, listing)
|
||||
} catch (error) {
|
||||
console.log("Failed to add contact: ", error)
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user