mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +00:00
styling: Enforced styling across all files (#55)
This commit is contained in:
165 files changed
+1879
-1725
No files matched your search
+46
-42
@@ -1,15 +1,18 @@
|
||||
import events from '../utils/events';
|
||||
import { ESX } from './server';
|
||||
import events from "../utils/events";
|
||||
import { ESX } from "./server";
|
||||
import { getSource } from "./functions";
|
||||
import { pool } from './db';
|
||||
import { Transfer, IBankCredentials } from '../../phone/src/common/typings/bank';
|
||||
import { useIdentifier } from './functions';
|
||||
import { type } from 'os';
|
||||
|
||||
import { pool } from "./db";
|
||||
import {
|
||||
Transfer,
|
||||
IBankCredentials,
|
||||
} from "../../phone/src/common/typings/bank";
|
||||
import { useIdentifier } from "./functions";
|
||||
import { type } from "os";
|
||||
|
||||
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 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;
|
||||
@@ -17,45 +20,47 @@ async function fetchAllTransactions(identifier: string): Promise<Transfer[]> {
|
||||
|
||||
function fetchCredentials(): IBankCredentials {
|
||||
const name = ESX.GetPlayerFromId(getSource()).getName();
|
||||
const balance = ESX.GetPlayerFromId(getSource()).getAccount('bank').money
|
||||
const balance = ESX.GetPlayerFromId(getSource()).getAccount("bank").money;
|
||||
|
||||
const result = {
|
||||
name,
|
||||
balance
|
||||
}
|
||||
balance,
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async function addTransfer(identifier: string, transfer: Transfer): Promise<any> {
|
||||
const xPlayer = ESX.GetPlayerFromId(getSource())
|
||||
const bankBalance = xPlayer.getAccount('bank').money;
|
||||
const sourceName = xPlayer.getName()
|
||||
async function addTransfer(
|
||||
identifier: string,
|
||||
transfer: Transfer
|
||||
): Promise<any> {
|
||||
const xPlayer = ESX.GetPlayerFromId(getSource());
|
||||
const bankBalance = xPlayer.getAccount("bank").money;
|
||||
const sourceName = xPlayer.getName();
|
||||
|
||||
const xTarget = ESX.GetPlayerFromId(transfer.targetID);
|
||||
|
||||
|
||||
if (transfer.transferAmount > bankBalance) {
|
||||
emitNet(events.BANK_TRANSACTION_ALERT, getSource(), false)
|
||||
}
|
||||
else if (transfer.transferAmount < bankBalance) {
|
||||
emitNet(events.BANK_TRANSACTION_ALERT, getSource(), false);
|
||||
} else if (transfer.transferAmount < bankBalance) {
|
||||
emitNet(events.BANK_TRANSACTION_ALERT, getSource(), true);
|
||||
|
||||
xTarget.addAccountMoney('bank', transfer.transferAmount);
|
||||
xPlayer.removeAccountMoney('bank', transfer.transferAmount);
|
||||
xTarget.addAccountMoney("bank", transfer.transferAmount);
|
||||
xPlayer.removeAccountMoney("bank", transfer.transferAmount);
|
||||
|
||||
const query =
|
||||
"INSERT INTO npwd_bank_transfers (identifier, target, amount, message, type, source) VALUES (?, ?, ?, ?, ?, ?)";
|
||||
|
||||
const query = "INSERT INTO npwd_bank_transfers (identifier, target, amount, message, type, source) VALUES (?, ?, ?, ?, ?, ?)"
|
||||
|
||||
const [results] = await pool.query(query, [
|
||||
identifier,
|
||||
identifier,
|
||||
transfer.targetID,
|
||||
transfer.transferAmount,
|
||||
transfer.message,
|
||||
"Transfer",
|
||||
sourceName,
|
||||
])
|
||||
]);
|
||||
const insertData = <any>results;
|
||||
return await getTransfer(insertData.insertId)
|
||||
return await getTransfer(insertData.insertId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,43 +69,42 @@ async function addTransfer(identifier: string, transfer: Transfer): Promise<any>
|
||||
* @param transferId - transfer id
|
||||
*/
|
||||
async function getTransfer(transferId: number): Promise<Transfer> {
|
||||
const query = "SELECT * FROM npwd_bank_transfers WHERE id = ?"
|
||||
const [ results ] = await pool.query(query, [transferId]);
|
||||
const query = "SELECT * FROM npwd_bank_transfers WHERE id = ?";
|
||||
const [results] = await pool.query(query, [transferId]);
|
||||
const transfers = <Transfer[]>results;
|
||||
const transfer = transfers[0];
|
||||
return {...transfer};
|
||||
return { ...transfer };
|
||||
}
|
||||
|
||||
onNet(events.BANK_FETCH_TRANSACTIONS, async () => {
|
||||
try {
|
||||
const _source = (global as any).source;
|
||||
const _identifier = await useIdentifier()
|
||||
const _identifier = await useIdentifier();
|
||||
const transfer = await fetchAllTransactions(_identifier);
|
||||
|
||||
emitNet(events.BANK_SEND_TRANSFERS, _source, transfer)
|
||||
|
||||
emitNet(events.BANK_SEND_TRANSFERS, _source, transfer);
|
||||
} catch (error) {
|
||||
console.log("Failed to fetch transactions");
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
onNet(events.BANK_ADD_TRANSFER, async (transfer: Transfer) => {
|
||||
const xTarget = ESX.GetPlayerFromId(transfer.targetID);
|
||||
try {
|
||||
const _identifier = await useIdentifier()
|
||||
const transferNotify = await addTransfer(_identifier, transfer)
|
||||
emitNet(events.BANK_TRANSACTION_NOTIFICATION, xTarget, transferNotify)
|
||||
const _identifier = await useIdentifier();
|
||||
const transferNotify = await addTransfer(_identifier, transfer);
|
||||
emitNet(events.BANK_TRANSACTION_NOTIFICATION, xTarget, transferNotify);
|
||||
emitNet(events.BANK_ADD_TRANSFER_SUCCESS, getSource());
|
||||
} catch (error) {
|
||||
emitNet(events.BANK_TRANSACTION_ALERT, getSource(), false)
|
||||
emitNet(events.BANK_TRANSACTION_ALERT, getSource(), false);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
onNet(events.BANK_GET_CREDENTIALS, () => {
|
||||
try {
|
||||
const credentials = fetchCredentials()
|
||||
emitNet(events.BANK_SEND_CREDENTIALS, getSource(), credentials)
|
||||
const credentials = fetchCredentials();
|
||||
emitNet(events.BANK_SEND_CREDENTIALS, getSource(), credentials);
|
||||
} catch (error) {
|
||||
console.log("Failed to fetch credentials");
|
||||
}
|
||||
})
|
||||
});
|
||||
Reference in new issue
Block a user