bank cleanup

This commit is contained in:
Christopher committed 2021-01-03 21:42:13 +01:00
1 parent d0ed913d7c
commit 6ee401e3d5
1 file changed
+9 -16
+9 -16
View File
@@ -1,30 +1,24 @@
import events from '../utils/events';
import { ESX } from './server';
import { getSource } from "./functions";
import { pool } from './db';
import { Transfer, Credentials } from '../../phone/src/common/interfaces/bank';
import { useIdentifier } from './functions';
import { type } from 'os';
import {ESX} from './server';
import {getSource, useIdentifier} from "./functions";
import {pool} from './db';
import {IBankCredentials, Transfer} from '../../phone/src/common/typings/bank';
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;
return <Transfer[]>results;
}
function fetchCredentials(): Credentials {
function fetchCredentials(): IBankCredentials {
const name = ESX.GetPlayerFromId(getSource()).getName();
const balance = ESX.GetPlayerFromId(getSource()).getAccount('bank').money
const result = {
return {
name,
balance
}
return result;
};
}
async function addTransfer(identifier: string, transfer: Transfer): Promise<any> {
@@ -86,11 +80,10 @@ onNet(events.BANK_FETCH_TRANSACTIONS, async () => {
onNet(events.BANK_ADD_TRANSFER, async (transfer: Transfer) => {
const xTarget = ESX.GetPlayerFromId(transfer.targetID);
const targetSource = xTarget.source;
try {
const _identifier = await useIdentifier()
const transferNotify = await addTransfer(_identifier, transfer)
emitNet(events.BANK_TRANSACTION_NOTIFICATION, targetSource, transferNotify)
emitNet(events.BANK_TRANSACTION_NOTIFICATION, xTarget, transferNotify)
emitNet(events.BANK_ADD_TRANSFER_SUCCESS, getSource());
} catch (error) {
emitNet(events.BANK_TRANSACTION_ALERT, getSource(), false)