mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
Merge pull request #18 from Re-Ignited-Development/feat/bank
Feat/bank - need to fix backend for transactions
This commit is contained in:
27 files changed
+872
-50
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import events from '../utils/events';
|
||||
|
||||
|
||||
onNet(events.BANK_SEND_TRANSFERS, (transfer: any) => {
|
||||
SendNuiMessage(
|
||||
JSON.stringify({
|
||||
app: "BANK",
|
||||
method: "setTransaction",
|
||||
data: transfer
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
onNet(events.BANK_SEND_CREDENTIALS, (credentials: any) => {
|
||||
console.log("Client:", credentials.balance, credentials.name)
|
||||
SendNuiMessage(
|
||||
JSON.stringify({
|
||||
app: "BANK",
|
||||
method: "setCredentials",
|
||||
data: credentials
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
RegisterNuiCallbackType(events.BANK_ADD_TRANSFER);
|
||||
on(`__cfx_nui:${events.BANK_ADD_TRANSFER}`, (data: any) => {
|
||||
const transfer = data;
|
||||
emitNet(events.BANK_ADD_TRANSFER, transfer)
|
||||
|
||||
setTimeout(() => {
|
||||
emitNet(events.BANK_FETCH_TRANSACTIONS);
|
||||
}, 500)
|
||||
})
|
||||
@@ -237,6 +237,8 @@ async function Phone() {
|
||||
emitNet('phone:getCredentials')
|
||||
emitNet(events.CONTACTS_GET_CONTACTS);
|
||||
emitNet(events.SELLOUT_FETCH_LISTING);
|
||||
emitNet(events.BANK_FETCH_TRANSACTIONS);
|
||||
emitNet(events.BANK_GET_CREDENTIALS);
|
||||
console.log("Sellout fetched from client side")// Gets the credentials. Will eventually most likely only get the phone number and name, idk.
|
||||
SetCursorLocation(0.90, 0.922) //Experimental
|
||||
let res = GetActiveScreenResolution()
|
||||
@@ -274,6 +276,8 @@ async function Phone() {
|
||||
emitNet('phone:getCredentials')
|
||||
emitNet(events.CONTACTS_GET_CONTACTS);
|
||||
emitNet(events.SELLOUT_FETCH_LISTING);
|
||||
emitNet(events.BANK_FETCH_TRANSACTIONS);
|
||||
emitNet(events.BANK_GET_CREDENTIALS);
|
||||
console.log("Sellout fetched from client side")
|
||||
SetCursorLocation(0.936, 0.922) //Experimental
|
||||
let res = GetActiveScreenResolution()
|
||||
|
||||
@@ -3,6 +3,7 @@ import './cl_main';
|
||||
import './cl_twitter';
|
||||
import './cl_contacts';
|
||||
import './cl_sellout';
|
||||
import './cl_bank';
|
||||
|
||||
export let ESX: ESXClient = null;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import './sv_twitter';
|
||||
import './sv_main';
|
||||
import './sv_contacts';
|
||||
import './sv_sellout';
|
||||
import './sv_bank';
|
||||
|
||||
export let ESX: ESXServer = null;
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import events from '../utils/events';
|
||||
import { ESX, getSource } from './server';
|
||||
import { pool } from './db';
|
||||
import { resourceLimits } from 'worker_threads';
|
||||
|
||||
interface Transfer {
|
||||
targetID: string;
|
||||
amount: number;
|
||||
message: string;
|
||||
}
|
||||
|
||||
interface Credentials {
|
||||
name: string;
|
||||
balance: number;
|
||||
}
|
||||
|
||||
|
||||
async function fetchAllTransactions(identifier: string): Promise<Transfer[]> {
|
||||
const query = "SELECT * FROM npwd_bank_transfers WHERE identifier = ? ORDER BY id DESC"
|
||||
const [ results ] = await pool.query(query, [identifier])
|
||||
const transactions = <Transfer[]>results;
|
||||
|
||||
return transactions;
|
||||
}
|
||||
|
||||
function fetchCredentials(): Credentials {
|
||||
const name = ESX.GetPlayerFromId(getSource()).getName();
|
||||
const balance = ESX.GetPlayerFromId(getSource()).getAccount('bank').money
|
||||
|
||||
const result = {
|
||||
name,
|
||||
balance
|
||||
}
|
||||
|
||||
console.log(result.name, result.balance);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
async function addTransfer(identifier: string, transfer: Transfer): Promise<any> {
|
||||
|
||||
const xPlayer = ESX.GetPlayerFromId(getSource())
|
||||
const bankBalance = xPlayer.getAccount('bank').money;
|
||||
console.log(bankBalance)
|
||||
if (transfer.amount > bankBalance) {
|
||||
console.log("poor man")
|
||||
emitNet(events.BANK_TRANSACTION_ALERT, getSource, 'You do not have enough money on your account', 'error')
|
||||
}
|
||||
else if (transfer.amount <= bankBalance) {
|
||||
const query = "INSERT INTO npwd_bank_transfers (identifier, target, amount, message) VALUES (?, ?, ?, ?)"
|
||||
|
||||
await pool.query(query, [
|
||||
identifier,
|
||||
transfer.targetID,
|
||||
transfer.amount,
|
||||
transfer.message
|
||||
])
|
||||
emitNet(events.BANK_TRANSACTION_ALERT, getSource, 'You succesfully transferred money to someone', 'success')
|
||||
}
|
||||
}
|
||||
|
||||
onNet(events.BANK_FETCH_TRANSACTIONS, async () => {
|
||||
try {
|
||||
const _source = (global as any).source;
|
||||
const _identifier = ESX.GetPlayerFromId(getSource()).getIdentifier()
|
||||
const transfer = await fetchAllTransactions(_identifier);
|
||||
|
||||
emitNet(events.BANK_SEND_TRANSFERS, _source, transfer)
|
||||
console.log("WOORK")
|
||||
|
||||
} catch (error) {
|
||||
console.log('Failed to fetch transactions', error)
|
||||
}
|
||||
})
|
||||
|
||||
onNet(events.BANK_ADD_TRANSFER, (transfer: Transfer) => {
|
||||
try {
|
||||
const _identifier = ESX.GetPlayerFromId(getSource()).getIdentifier()
|
||||
addTransfer(_identifier, transfer)
|
||||
} catch (error) {
|
||||
console.log('Failed to add transfer', error)
|
||||
}
|
||||
})
|
||||
|
||||
onNet(events.BANK_GET_CREDENTIALS, () => {
|
||||
try {
|
||||
const credentials = fetchCredentials()
|
||||
console.log("New log: ", credentials.balance, credentials.name)
|
||||
emitNet(events.BANK_SEND_CREDENTIALS, getSource(), credentials)
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
})
|
||||
@@ -31,5 +31,13 @@ export default {
|
||||
// Sellout
|
||||
SELLOUT_ADD_LISTING: 'phone:addListing',
|
||||
SELLOUT_FETCH_LISTING: 'phone:fetchAllListings',
|
||||
SELLOUT_SEND_LISTING: 'phone:sendAllListings'
|
||||
SELLOUT_SEND_LISTING: 'phone:sendAllListings',
|
||||
|
||||
// Bank
|
||||
BANK_ADD_TRANSFER: 'phone:addTransfer',
|
||||
BANK_FETCH_TRANSACTIONS: 'phone:fetchAllTransactions',
|
||||
BANK_SEND_TRANSFERS: 'phone:sendTransfers',
|
||||
BANK_TRANSACTION_ALERT: 'phone:transactionAlert',
|
||||
BANK_SEND_CREDENTIALS: 'phone:sendBankCredentials',
|
||||
BANK_GET_CREDENTIALS: 'phone:getBankCredentials'
|
||||
}
|
||||
Reference in new issue
Block a user