Skip to content

Commit a383c4b

Browse files
committed
Destructure wallet constant
1 parent 7148417 commit a383c4b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

services/tradingService.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const transactionsModel = firestore.collection('transactions')
44
const tradeLogsModel = firestore.collection('trade-logs')
55
const { fetchWallet, updateWallet } = require('../models/wallets')
66
const { fetchUserStocks, updateUserStocks } = require('../models/stocks')
7-
const walletConstants = require('../constants/wallets')
7+
const { DINERO } = require('../constants/wallets')
88

99
const INSUFFICIENT_FUNDS = 'Trade was not successful due to insufficient funds'
1010
const INSUFFICIENT_QUANTITIES = 'Trade was not successful because you do not have enough quantity'
@@ -53,17 +53,17 @@ const trade = async (tradeData) => {
5353
}
5454

5555
quantityToUpdate = quantity + stockData.quantity
56-
userBalance = (quantity * stockData.price) + currencies[walletConstants.DINERO]
56+
userBalance = (quantity * stockData.price) + currencies[`${DINERO}`]
5757
userStocksQty = userStocks.quantity - quantity
5858
break
5959
}
6060
case 'BUY': {
6161
qtyUserCanPurchase = Math.floor(totalPrice / stockData.price)
62-
if (qtyUserCanPurchase <= 0 || totalPrice > currencies[walletConstants.DINERO]) {
62+
if (qtyUserCanPurchase <= 0 || totalPrice > currencies[`${DINERO}`]) {
6363
return { canUserTrade: false, errorMessage: INSUFFICIENT_FUNDS }
6464
}
6565
quantityToUpdate = stockData.quantity - qtyUserCanPurchase
66-
userBalance = currencies[walletConstants.DINERO] - (qtyUserCanPurchase * stockData.price)
66+
userBalance = currencies[`${DINERO}`] - (qtyUserCanPurchase * stockData.price)
6767
userStocksQty = qtyUserCanPurchase
6868

6969
initialStockValue = stockData.price
@@ -81,7 +81,7 @@ const trade = async (tradeData) => {
8181

8282
const orderValue = qtyUserCanPurchase * stockData.price
8383
const stockPriceToBeUpdated = getUpdatedPrice(stockData.price)
84-
updatedCurrencyData[walletConstants.DINERO] = userBalance
84+
updatedCurrencyData[`${DINERO}`] = userBalance
8585

8686
const updatedStockData = {
8787
...stockData,

0 commit comments

Comments
 (0)