@@ -4,7 +4,7 @@ const transactionsModel = firestore.collection('transactions')
4
4
const tradeLogsModel = firestore . collection ( 'trade-logs' )
5
5
const { fetchWallet, updateWallet } = require ( '../models/wallets' )
6
6
const { fetchUserStocks, updateUserStocks } = require ( '../models/stocks' )
7
- const walletConstants = require ( '../constants/wallets' )
7
+ const { DINERO } = require ( '../constants/wallets' )
8
8
9
9
const INSUFFICIENT_FUNDS = 'Trade was not successful due to insufficient funds'
10
10
const INSUFFICIENT_QUANTITIES = 'Trade was not successful because you do not have enough quantity'
@@ -53,17 +53,17 @@ const trade = async (tradeData) => {
53
53
}
54
54
55
55
quantityToUpdate = quantity + stockData . quantity
56
- userBalance = ( quantity * stockData . price ) + currencies [ walletConstants . DINERO ]
56
+ userBalance = ( quantity * stockData . price ) + currencies [ ` ${ DINERO } ` ]
57
57
userStocksQty = userStocks . quantity - quantity
58
58
break
59
59
}
60
60
case 'BUY' : {
61
61
qtyUserCanPurchase = Math . floor ( totalPrice / stockData . price )
62
- if ( qtyUserCanPurchase <= 0 || totalPrice > currencies [ walletConstants . DINERO ] ) {
62
+ if ( qtyUserCanPurchase <= 0 || totalPrice > currencies [ ` ${ DINERO } ` ] ) {
63
63
return { canUserTrade : false , errorMessage : INSUFFICIENT_FUNDS }
64
64
}
65
65
quantityToUpdate = stockData . quantity - qtyUserCanPurchase
66
- userBalance = currencies [ walletConstants . DINERO ] - ( qtyUserCanPurchase * stockData . price )
66
+ userBalance = currencies [ ` ${ DINERO } ` ] - ( qtyUserCanPurchase * stockData . price )
67
67
userStocksQty = qtyUserCanPurchase
68
68
69
69
initialStockValue = stockData . price
@@ -81,7 +81,7 @@ const trade = async (tradeData) => {
81
81
82
82
const orderValue = qtyUserCanPurchase * stockData . price
83
83
const stockPriceToBeUpdated = getUpdatedPrice ( stockData . price )
84
- updatedCurrencyData [ walletConstants . DINERO ] = userBalance
84
+ updatedCurrencyData [ ` ${ DINERO } ` ] = userBalance
85
85
86
86
const updatedStockData = {
87
87
...stockData ,
0 commit comments