Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mongo-restart: mongo-stop mongo-start

mongo-reset: mongo-stop
docker rm -f tradenote_db
docker volume rm -f $$(docker volume ls)
$(MAKE) mongo-start

node-env-prep:
Expand Down
48 changes: 33 additions & 15 deletions src/utils/addTrades.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export async function useGetExistingTradesArray(param99, param0) {

export async function useImportTrades(param1, param2, param3, param0) {
return new Promise(async (resolve, reject) => {
// reset accounts list for this import to avoid duplicates from previous files
tradeAccounts.length = 0

//console.log("param1 " + param1)
//console.log("param2 " + param2)
//console.log("param3 " + param3)
Expand Down Expand Up @@ -394,9 +397,13 @@ async function createTempExecutions() {
for (const key of keys) {
try {
let temp2 = {};
temp2.account = tradesData[key].Account
// normalise account and drop blanks
let acctVal = tradesData[key].Account ? tradesData[key].Account.toString().trim() : ""
temp2.account = acctVal
temp2.broker = selectedBroker.value
if (!tradeAccounts.includes(tradesData[key].Account)) tradeAccounts.push(tradesData[key].Account)
if (acctVal && !tradeAccounts.includes(acctVal)) {
tradeAccounts.push(acctVal)
}
/*usDate = dayjs.tz("07/22/2021 00:00:00", 'MM/DD/YYYY 00:00:00', "UTC")
//frDate = usDate.tz("Europe/Paris")
console.log("date "+usDate+" and fr ")*/
Expand Down Expand Up @@ -2101,8 +2108,14 @@ export async function useUploadTrades(param99, param0) {
const results = await query.first(param99 === "api" ? { useMasterKey: true } : undefined);
//console.log(" results "+JSON.stringify(results))
if (results) {
results.set("accounts", param)
//console.log("param 2" + JSON.stringify(param2))
// remove any empty account objects before saving
const cleanAccounts = Array.isArray(param)
? param.filter(a => a && a.value && a.value.toString().trim())
: param
results.set("accounts", cleanAccounts)
// update local user copy so subsequent imports see the change
currentUser.value.accounts = cleanAccounts
//console.log("param 2" + JSON.stringify(param2))
if (param99 === "api") {
await results.save(null, { useMasterKey: true }) //very important to have await or else too quick to update
} else {
Expand All @@ -2123,8 +2136,10 @@ export async function useUploadTrades(param99, param0) {
} else {
selectedItemsArray = []
}
//console.log(" selected items value " + JSON.stringify(selectedItemsArray))
selectedItemsArray.push(param2)
// only add the entry if it isn't already present and not empty
if (param2 && !selectedItemsArray.includes(param2)) {
selectedItemsArray.push(param2)
}
localStorage.setItem(selectedItems, selectedItemsArray)
//console.log(" -> Updated selectedItems / localstorage " + selectedItemsArray)
}
Expand All @@ -2135,25 +2150,28 @@ export async function useUploadTrades(param99, param0) {

if (currentUser.value.accounts) {
tradeAccounts.forEach(element => {
let check = currentUser.value.accounts.find(x => x.value == element)
//console.log("check "+JSON.stringify(check))
const acct = (typeof element === 'string' ? element.trim() : element)
if (!acct) return // skip blank
let check = currentUser.value.accounts.find(x => x.value == acct)
if (!check) {
let tempArray = currentUser.value.accounts
let tempArray = currentUser.value.accounts.slice() // copy existing array
let temp = {}
temp.value = tradeAccounts[0]
temp.label = tradeAccounts[0]
temp.value = acct
temp.label = acct
tempArray.push(temp)
updateTradeAccounts(tempArray, temp.value)
updateTradeAccounts(tempArray, acct)
}
});
} else {
let tempArray = []
tradeAccounts.forEach(element => {
const acct = (typeof element === 'string' ? element.trim() : element)
if (!acct) return
let temp = {}
temp.value = element
temp.label = element
temp.value = acct
temp.label = acct
tempArray.push(temp)
updateTradeAccounts(tempArray, temp.value)
updateTradeAccounts(tempArray, acct)
})
}
})
Expand Down
5 changes: 4 additions & 1 deletion src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,10 @@ export async function useSetValues() {

if (Object.is(localStorage.getItem('selectedAccounts'), null) && currentUser.value && currentUser.value.hasOwnProperty("accounts") && currentUser.value.accounts.length > 0) {
currentUser.value.accounts.forEach(element => {
selectedAccounts.value.push(element.value)
if (element && element.value) {
const acct = element.value.toString().trim()
if (acct) selectedAccounts.value.push(acct)
}
});
//console.log("selected accounts " + JSON.stringify(selectedAccounts))
localStorage.setItem('selectedAccounts', selectedAccounts.value)
Expand Down
Loading